How to get the values into the textbox using datareader in asp.net
-
hi, i am very new to this .net world. I like to get the values from the database into the textbox using datareader. I tried in this way : sqlcommand com=new sqlcommand(query,connectionstring); datareader rdr=com.executereader(); while(rdr.read()) { textbox.text=rdr["fieldname"].getstring(); } But i failed to get the values plz help me....in getting the values into the textbox using datareader plz post the codesnippet how to do it Thanx in advance :)
-
hi, i am very new to this .net world. I like to get the values from the database into the textbox using datareader. I tried in this way : sqlcommand com=new sqlcommand(query,connectionstring); datareader rdr=com.executereader(); while(rdr.read()) { textbox.text=rdr["fieldname"].getstring(); } But i failed to get the values plz help me....in getting the values into the textbox using datareader plz post the codesnippet how to do it Thanx in advance :)
There could be few issues that u need to resolve for this code. Firstly if you are having multiple rows in your database and you are trying to fetch those values in a single text box using DataReader then only the last record would be visible to you as the TextBox will be set to the last value only..... Secondly for using DataReader and SqlCommand you need an open connection so you need to specify an sqlconnection object and put it like
SqlConnection con = new SqlConnection();
con.Open();
sqlcommand com=new sqlcommand(query,con);
DataReader dr=com.ExecuteReader();
while(rdr.read())
{
textbox.text=rdr["fieldname"].getstring();
}
con.Close();As DataReader is readonly and forward only so only the last value is available to the TextBox control. To avoid that and to retrieve all the values try some listbox or combobox. Best of luck!!! Try hard but don't get stubborn
-
hi, i am very new to this .net world. I like to get the values from the database into the textbox using datareader. I tried in this way : sqlcommand com=new sqlcommand(query,connectionstring); datareader rdr=com.executereader(); while(rdr.read()) { textbox.text=rdr["fieldname"].getstring(); } But i failed to get the values plz help me....in getting the values into the textbox using datareader plz post the codesnippet how to do it Thanx in advance :)
As you are new in .Net World,I will suggest you to buy some Beginners Book and start reading yourself. Which will help you learn better. :) Good Luck !
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net
-
hi, i am very new to this .net world. I like to get the values from the database into the textbox using datareader. I tried in this way : sqlcommand com=new sqlcommand(query,connectionstring); datareader rdr=com.executereader(); while(rdr.read()) { textbox.text=rdr["fieldname"].getstring(); } But i failed to get the values plz help me....in getting the values into the textbox using datareader plz post the codesnippet how to do it Thanx in advance :)