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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assigning database record values to text box using for loop

Status
Not open for further replies.

nitehawk416

Programmer
Feb 17, 2009
2
US
Hi, i just joined here, I have a question about assigning values from a dataset. I have an access database linked to my C# app, and i want to basically loop through the records and have it update the value in the text box with each loop, heres what i have so far...

for (int i = 0; i < XMLDataDataSet1.Tables["tblNPX"].Rows.Count; i++)
{
txtNPA.Text = xMLDataDataSet1.Tables["tblNPX"].Rows["NPA"].ToString();
}

so i want it to when i click a button pull the first record, put the value in the text box, then pull the second record, change the txtbox value to the second record, until the EOF.

I get no errors in my code when i run it, it just doesnt do what i want it to. the text box stays blank.

Thanks in advance.
 
Hi,

Can I ask why you want to loop through each record? The textbox will only ever display the last record in your table.

Are you familiar with debugging? You should create checkpoints in your code and step through each line to determine the problem.

A possible reason here is that your table is empty, or the last record in your table has an empty value.

Ryan
 
hi, thanks for the response, i actually figured it out though. turns out i forgot to bind the column to my textbox as the datasource...

thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top