Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Info from Dataset 1

Status
Not open for further replies.

rahmanjan

Programmer
Apr 13, 2003
180
AU
Hi guys,

Let is say i have a dataset with one record (returning searching criteria). How can I get the data from this dataset to fill the Controls in GUI eg Textbox or Label etc.

1 - I want to know how can i loop through the data in the dataset - without binding?

2- Also if i can bind it to textboxes / Labels?

Ta
 
Hey rahmanjan,

Looping through a dataset is rather straightforward using the foreach structure.

Here is a quick example of how to set your controls with a foreach loop.

// assuming all objects are properly filled
foreach( DataRow r in ds.Tables[0].Rows )
{
label1.Text = r["col1"].ToString();
// OR label1.Text = r[0].ToString();
}

If you knew for sure you only had one record, you wouldn't need to loop obviously.

As for binding the controls directly to the dataset, you need to set add the dataset table and field to the databindings property.

// through code
textbox1.DataBindings.Add( "Text", ds.Tables[0], "col1" );

You can do this through the designer, under Databindings - Advanced propety manager of the control.

I hope this helps,

------------------------------------------
Steen Bray
Kermode Computing Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top