How to bind a label to a dataset with C#

I have a project class. The method GetRecordCover returns a dataset:

public DataTable GetRecordCover(string id)
{
	string str = “SELECT * FROM RecordCover WHERE=’” + “id” + “’”;
	
	SqlConnection cn = new SqlConnection(_connectionString);
	SqlDataAdapter da = new SqlDataAdapter(sql, cn);

	DataSet ds = new DataSet();
	da.Fill(ds, “RecordCover”);

	// Get data table
	DataTable dt = ds.Tables[“RecordCover”];
	
	Return ds.Tables[0];

	//ds.Tables[0].Rows[0][0];
	//ds.Tables[0].Rows[0][1];
	//ds.Tables[0].Rows[0][2];
}

In the web form's code behind I want:

RecordCover rc = new RecordCover();

label1.text = how do populate my label with ds.Tables[0].Rows[0][0];
label2.text = how do populate my label with ds.Tables[0].Rows[0][1];
label3.text = how do populate my label with ds.Tables[0].Rows[0][2]; ???


0
Utf
1/20/2010 4:39:01 PM
dotnet.framework.aspnet 1425 articles. 0 followers. Follow

4 Replies
748 Views

Similar Articles

[PageSpeed] 19

bthumber wrote:
> I have a project class. The method GetRecordCover returns a dataset:
> 
> public DataTable GetRecordCover(string id)
> {
> 	string str = “SELECT * FROM RecordCover WHERE=’” + “id” + “’”;
> 	
> 	SqlConnection cn = new SqlConnection(_connectionString);
> 	SqlDataAdapter da = new SqlDataAdapter(sql, cn);
> 
> 	DataSet ds = new DataSet();
> 	da.Fill(ds, “RecordCover”);
> 
> 	// Get data table
> 	DataTable dt = ds.Tables[“RecordCover”];
> 	
> 	Return ds.Tables[0];
> 
> 	//ds.Tables[0].Rows[0][0];
> 	//ds.Tables[0].Rows[0][1];
> 	//ds.Tables[0].Rows[0][2];
> }
> 
> In the web form's code behind I want:
> 
> RecordCover rc = new RecordCover();
> 
> label1.text = how do populate my label with ds.Tables[0].Rows[0][0];
> label2.text = how do populate my label with ds.Tables[0].Rows[0][1];
> label3.text = how do populate my label with ds.Tables[0].Rows[0][2]; ???
> 

label3.Text = dt.Rows[0][1].ToString();

btw, you can name your columns, making you code more readable and less 
breakable in case a column is added to the source table.  Like this:


Label_addr4.Text = dtEvents.Rows[0]["addr4"].ToString();





0
James
1/20/2010 6:04:39 PM
James...remember the label is not in the project so don't I need an instance 
of the class and make a call to that method? i.e. 

RecordCover rc = new RecordCover();  

then rc.GetRecordCover("id");



"James Irvine" wrote:

> bthumber wrote:
> > I have a project class. The method GetRecordCover returns a dataset:
> > 
> > public DataTable GetRecordCover(string id)
> > {
> > 	string str = “SELECT * FROM RecordCover WHERE=’” + “id” + “’”;
> > 	
> > 	SqlConnection cn = new SqlConnection(_connectionString);
> > 	SqlDataAdapter da = new SqlDataAdapter(sql, cn);
> > 
> > 	DataSet ds = new DataSet();
> > 	da.Fill(ds, “RecordCover”);
> > 
> > 	// Get data table
> > 	DataTable dt = ds.Tables[“RecordCover”];
> > 	
> > 	Return ds.Tables[0];
> > 
> > 	//ds.Tables[0].Rows[0][0];
> > 	//ds.Tables[0].Rows[0][1];
> > 	//ds.Tables[0].Rows[0][2];
> > }
> > 
> > In the web form's code behind I want:
> > 
> > RecordCover rc = new RecordCover();
> > 
> > label1.text = how do populate my label with ds.Tables[0].Rows[0][0];
> > label2.text = how do populate my label with ds.Tables[0].Rows[0][1];
> > label3.text = how do populate my label with ds.Tables[0].Rows[0][2]; ???
> > 
> 
> label3.Text = dt.Rows[0][1].ToString();
> 
> btw, you can name your columns, making you code more readable and less 
> breakable in case a column is added to the source table.  Like this:
> 
> 
> Label_addr4.Text = dtEvents.Rows[0]["addr4"].ToString();
> 
> 
> 
> 
> 
> .
> 
0
Utf
1/20/2010 8:25:02 PM
bthumber wrote:
> James...remember the label is not in the project so don't I need an instance 
> of the class and make a call to that method? i.e. 
> 
> RecordCover rc = new RecordCover();  
> 
> then rc.GetRecordCover("id");


yes.  Here's an example:

     protected void getEvents()
     {
         getEvents cx = new getEvents();
         DataTable dtEvents = new DataTable();

         dtEvents = cx.Get_Events();  // get all events


         if (dtEvents.Rows.Count > 0)
         {

             // 1st event:
             Label_Headline.Text = 	 
dtEvents.Rows[0]["headline"].ToString();

}

etc...
0
James
1/20/2010 10:32:15 PM
Thanks!

"James Irvine" wrote:

> bthumber wrote:
> > James...remember the label is not in the project so don't I need an instance 
> > of the class and make a call to that method? i.e. 
> > 
> > RecordCover rc = new RecordCover();  
> > 
> > then rc.GetRecordCover("id");
> 
> 
> yes.  Here's an example:
> 
>      protected void getEvents()
>      {
>          getEvents cx = new getEvents();
>          DataTable dtEvents = new DataTable();
> 
>          dtEvents = cx.Get_Events();  // get all events
> 
> 
>          if (dtEvents.Rows.Count > 0)
>          {
> 
>              // 1st event:
>              Label_Headline.Text = 	 
> dtEvents.Rows[0]["headline"].ToString();
> 
> }
> 
> etc...
> .
> 
0
Utf
1/21/2010 2:39:01 PM
Reply:

Similar Artilces:

creating labels?
How do I create 16 different labels on one sheet of labels. I can design a label and the same design will print on all sixteen, but want 16 different on the one sheet??? Setup your label page manually. Look at the label page setup for 16, duplicate the margins and gaps in the arrange menu. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Ray" <Ray@discussions.microsoft.com> wrote in message news:B2884E13-C74E-4FCE-B1C6-330CEBE4BD1F@microsoft.com... > How do I create 16 different labels on one sheet of labels. ...

label formating
I have a system with multiple labels. When a new front end is pushed out they all have to be reformated to the systems printer. I was thinking of creating a seperate access file to store just the labels (most updates don't require label changes). How can I print a report from a different database? That would be great. How do you format the label using VBA? "Dorian" wrote: > Why not keep the label formats in a table in the back-end to which each > front-end links. > -- Dorian > "Give someone a fish and they eat for a day; teach someone to fis...

How to calculate Yield using Yield Function by C#
Dear Excel Guruz.. I have to calculate Yield using excel yield function in my C# program.In order to do that I have import using Microsoft.Office.Core; using Excel = Microsoft.Office.Interop.Excel; and write yield calcuation function . My function work fine for office 2007 but onces I unistall 2007 , my code stopped wokring on any perivious version. What I have observed my last line i.e used to calculate yield has problem result = xl.Evaluate("YIELD(" + days + "," + days1 + "," + rate + "," + par + "," + facevalue + &...

programmatically change the binding order
All, How can I programmatically change the binding order of the network protocol in Win XP using VC++. Thanks in advance. ...

Independent data labels
Is there a way to apply data labels which are not the values used for plotting data (in a stacked bar chart)? Hi have a look at the following add-ins which will do this for you: http://j-walk.com/ss/excel/files/charttools.htm http://www.appspro.com/utilities/Labeler.asp -- Regards Frank Kabel Frankfurt, Germany Rob wrote: > Is there a way to apply data labels which are not the > values used for plotting data (in a stacked bar chart)? ...

How do I remove a gutter for a binding edge in Publisher 2007?
I started a document thinking I'd bind it on the left, but as it evolved, I will be binding it on top. I cannot find the place that lets me change this! The print preview, page setup etc. don't give me any options. This is a printer option. Look at your printer setup. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Mayaluga" <Mayaluga@discussions.microsoft.com> wrote in message news:7E8FE3F1-F81A-44D1-BE16-975F3CE7AEF4@microsoft.com... >I started a document thinking I'd bind it on the left, but as ...

Create Activity Mail in Incident from C#
Hello, There is a case: When someone sends e-mail to specific address it is retrieved by our soft, preprocessed (search for some stuff and other), then it is supposed to be put in CRM. I know how to create incident (case) but don't know how I'm supposed to add some activities to it. I have not found any fields indicating case id. And when I add this activity (I want to create e-mail) will it be put in history or somewhere else? I would like to put it in some kind of inbox or something - I'v seen that there is queue object but don't know if it will be suitable for this t...

Label printer for jewelry
I am looking for a label printer for jewelry such as necklace and earrings. I would like to use dumbell shape labels. I use "3 0f 9" barcode in RMS as I have 3 alphabetic proceeded by 3-6 numeric codes. I need to put a barcode, item number and price. The labels should be about 2 inches wide unfolded. What printer do you recommend that works easily with RMS? We use butterfly labels with cognitive advantage lx printer. Works fine but you will need to play with the labels a little bit until you set it up ok -----Original Message----- From: sammm [mailto:sammm@discussions.microsoft...

Adding data only if adjacent to cell labeled "male"/"female"
I have a spreadsheet that has this general format: column A column B Column C Column D 3 M 5 F 2 M 6 F Total Females: 11 Total Males: 5 For all the cells in Column A that are adjacent to a cell in column B containing a letter "F", I would a formula to add those numbers, and place the sum in column D (where I've t...

row and column labels #2
When opening a worksheet the row and column labels automatically appear as numbers instead of letters for columns and numbers for rows. What can I do? I found the answer to this question. You need to go into tool/options/general and uncheck the box next to R1:C1 "aron" wrote: > When opening a worksheet the row and column labels automatically appear as > numbers instead of letters for columns and numbers for rows. What can I do? Tools, Options, General, uncheck 'R1C1 reference style' Have a great day, Francis Hayes (The Excel Addict) http://www.TheExcelAddict....

Help requested for nested conditional formulas referencing other c
Hello--i can better explain the problem with an example: 24h 1wk change Person A 1 0 -1 Person B 0 1 1 Person C 0 0 0 Person D 0.25 0.25 0 Person E 0.5 Person F 1 0.5 -0.5 Person G 0 0.75 0.75 What I am trying to do is make three equations: 1 to calculate the average of the values in the 24h column, IF the value is NOT equal to zero, which I have accomplished with the array formula: {=AVERAGE(IF(B2:B8>0, B2:B8, ""))} here's where things get difficult--now, I want to find the average of the values in the 1wk column, only if either the values in the 24...

Binding a Textbox to a property
I have a property "TotalCost" of type int and a TextBox "tbTotalCost" in the main form "Form1" and was wondering how to bind one to the other tbTotalCost.DataBinding.Add("Text",this.TotalWinnings, erm); First peram. should be Property Name but in the examples Ive seen it usually has "Text". Guessing its because it is the Text property of the TextBox? Second peram. should be object DataSource. That the propery? Third should be DataMember. Erm... Flailing around a bit as you can see. mick "mick" <coughco...

Excel charting label assistance (Sydney Australia)
I need personal help with a simple Excel X/Y graph for one particular file. The data and graph plots a single patient's blood test results over time and I want to mark and label milestones along the way. In spite of many hours of Google research I have not been able to satisfactorily resolve my issues. I don't think that what I need is very hard (it eludes me) but the solution probably needs the services of a person who is well versed in the Graph functions (particularly labels). An Excel Graph expert in Sydney or Australia would probably be more appropriate but I&#...

Binding and lostfocus
I am using .NET Framework v2. I am binding properties to controls using complex binding. However until you tab off each control to lose focus the object being bound to is not updated. To get round this I am using SendKeys to tab on and off the control. This works fine but you have to put the sendkeys code in every event handler being bound to which is horrible. Is there a better way? Here are some code fragments. Protected m_BindingSource As BindingSource = New BindingSource UpdateBinding(chkWeek1Month1AtLeaving, "Checked", m_BindingSource, "Week1Month...

Where is Class Wizard in C++ 2005?
Hi, Its been a while since I worked in C++ and can't find my way in the new IDE. Basically I am looking for what was in version 6 the Class Wizard, because among other things, I want to make my CWnd derived class to handle the WM_MOVE message and thus I need an entry in, e.g.: //{{AFX_MSG(CSplitterFrame) //}}AFX_MSG -- Thanks in advance, Juan Dent, M.Sc. It is sort of dispersed into other menus. For example, you can right click on a control in a dialog and add and event or variable. It is not as convenient for C++/MFC as it was in V6, but it still works. You can also add ...

Paste Label into Workbook
I want to print information I extracted/copied/pasted into a Word 2003 document. I want to print it on an address label of 2 labels per A4 page seperated in middle horizontally. I can then peel it off and paste it into my A5 paper workbook I write notes in. To do so I need to print on one of the 2 labels and preferably vertically to look like a A5 page. Hope this make sense. Although you can certainly find a "label" definition that will give you two labels (portrait) per landscape page, much the easiest approach is to use the "2 pages per sheet" setting under ...

Printing Labels (continued)
For some reason I could not find the "Reply" button to reply to my previous post. It was helpful up to a point. fredq gave me code which started the printing from the designated spot, however, what I want is to only print (for example) label 8 which is on a sheet of 30 labels. This way I only print that name I want, The code fredq gave me started at label 8 and continued the rest of names. So thank you fredq and if you can help me to print only one label, that would be great. On Thu, 4 Oct 2007 05:10:00 -0700, Dar wrote: > For some reason I could not find the "Reply&qu...

how do you create file folder labels in excel?
"rebecca_vsp" <rebecca_vsp@discussions.microsoft.com> wrote in message news:25E65249-227E-44C4-8C40-EA997AD52650@microsoft.com... >nothing Please use this BIG WHITE SPACE to provide details of your question that won't fit in the subject line. Do you mean labels to stick on the spine of lever-arch files, for example? Word has built-in Label printing, with many different label formats already installed. Excel does not have this ability. (AFAIK....) Excel alone is poorly suited for creating labels. Do you have Word? Use Word's mailmerge with Excel or Access ...

ADP in A2007 Runtime: Traditional binding of form to stored procedure taking no parameters no longer works
Forms in ADP can have a stored procedure as the RecordSource. Traditionally we could write: RecordSource="dbo.EmployeesList" (or use the RecordSourceQualifier to specify "dbo"). On A2007 runtime this no longer works: The record source 'EmployeeList' specified on this form or report does not exist. On A2007 (with or without the /runtime command line switch) it does work. The only workaround I have found so far is to put the entire expression in the RecordSource property like this: "exec dbo.EmployeesList". I don't think this is an intentional change b...

label in chart
I have an XY chart and wish to assign a label to the x variable from third column of data, is ths possible: -- zac217 ----------------------------------------------------------------------- zac2170's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3647 View this thread: http://www.excelforum.com/showthread.php?threadid=56239 You can use Rob Bovey's XY Chart Labeler to add labels. It's a free add-in that you can download from his web site: http://www.appspro.com/Utilities/ChartLabeler.htm zac2170 wrote: > I have an XY chart and wish to assign...

socket
CSocket sock; if(sock.Create(0,SOCK_DGRAM,0) == false) { AfxMessageBox("Create"); return; } UINT portnr = 5000; if (sock.Bind(portnr,"10.0.0.10") == false) { int error = sock.GetLastError(); AfxMessageBox("Bind"); return; } When running this code I get an error 10022. According to msdn.microsoft.com it means : 10022 An invalid argument was supplied. WSAEINVAL What am I doing wrong ? Minor detail: it is silly to write "== false" because it might fool you into thinking that the opposite is "== true", which is not always the c...

Mass Price Update and Labels
I am in the process of becoming a member of a large hardware cooperative that sends out updated costs and prices based on market conditions. They have approx. 60K SKUs in their inventory - I probably would only carry a third of that amount. I know I should be able to import this in to the system on a regular basis, but is there a way I can print these labels out automatically based on what actually changed? On a different subject - right know I have approx 10K SKUs in my database, which lies on one of the POS stations (I have 4 POS stations total). The version of SQL is what automatica...

can't center a category label on a line chart
This is a multi-part message in MIME format. --------------000603030901060204040401 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, Yesterday I got some good help with figuring out the differences between the line chart and xy chart. I've had to go with the line chart. I've pretty much got it the way I want it. I've posted my data below. The < means prior to 2007. In Excel 2003 I could easily center the Year between the Major vertical gridlines (every forth one, since this is quarterly data). But with my pres...

getting data labels on xy chart from additional plot area
I am creating a scatter chart that is designed to show trends in employee performance. Employees are rated with 2 different tools, each using a 5 point scale. I am able to plot the intersection of each tool rating without a problem. However, I would like to be able to add a data label that is employee name. When I add names to the data series, my xy chart now plots each tool as a separate data point, not as an intersection. So...when I use source data like below, the chart looks fine, but employee name is not included. Tool 1 Tool2 ------------------- 4 5 3 ...

Picture on Barcode Label
Hi All, I want to print Item's picture on my barcode label in addition to the itemlookupcode and barcode. But the field for Picture object seems to take hardcoded file name instead of picking picture from the path stored in Item's table. Is it not possible to print item's picture on barcode labels? Asad ...