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

How to display data in Textboxes using DataReader

Status
Not open for further replies.

kebele

MIS
Joined
Jul 31, 2006
Messages
107
Location
US
I am displaying some of my fields from the database in to textboxes using datareader and bind it with gridview to display the rest of my fields using gridviw control ,however,The first row is missing from the gridview.Is this because the datareader already read the first row and when i bind it with the gridview it starts with the second row.How can i fix this problem?I am thinking to re-create datareader and bind it with gridview.can someone help me if i am doing it the right way. thanks



ItemReader1 = cmdItem.ExecuteReader()
ItemReader1.Read()
rtNumber.Text = ItemReader1("Route Number").ToString()
spNumber.Text = ItemReader1("S.P. Number").ToString()
cntId.Text = ItemReader1("contid").ToString()
txtLocation.Text = ItemReader1("loc").ToString()
lblCounty.Text = ItemReader1("County Name").ToString()
 
Is this because the datareader already read the first row and when i bind it with the gridview it starts with the second row
Yes, that is exactly the reason why.

Instead of using ExecuteReader and returning a reader, consider returning the data to a DataTable then you can access whatever values you want from the relevant row and still bind it to a GridView.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for your reply. Can you give me an example with this can be done. I have never dealt with datatable.
another question also, can i still display some of my fields in to a text box like what i did using data reader.
thanks
 
Search the FAQ's if you want an example


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks and I will search FAQ's to find an example.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top