Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please someone tell, after select the id from combobox, it shows in the text box only 1st record of the table, and other 2,3,4 is not showing, my code is

C#
cmd = new SqlCommand("select * from Images where id=" + DropDownList1.SelectedValue + "",con);
dr = cmd.ExecuteReader();

while(dr.Read ())
{
   TextBox1.Text = dr[1].ToString();
}



Pls, someone tell that why 2,3 and 4th id data is not showing.


Thanks.
Posted
Updated 21-Apr-11 2:16am
v2
Comments
willempipi 21-Apr-11 8:18am    
Check your DropDownList1.SelectedValue in debug to see which id you use. The code above should work, otherwise supply more code please.

Each time you overwrite the previous value. Try this:
TextBox1.Text += dr[1].ToString();


Check out the msdn where they output to the console. In that case all is shown because each value is automatically added (and not overwritten):
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx#Y2907[^]

Good luck!
 
Share this answer
 
v2
The question is not explanatory but can understand little bit.
Try like that.
TextBox1.Text += dr[1].ToString();
 
Share this answer
 
v2
Your SQL query is asking for a specific record matching one ID, that is why only one is showing.
 
Share this answer
 
SqlDataAdaptor adp=new SqlDataAdaptor("select * from Images where id=" + DropDownList1.SelectedValue + "",Con);
Dataset ds=new Dataset();

adp.Fill(ds);

for(int i=0;i<ds.tables[0].Rows.Count;i++)
{
TextBox1.text=ds.Tables[0].Rows[i]["FieldName"];

/* Here u use your own field I store it in TextBox. for your understand. */
}
 
Share this answer
 
Hi !!
You have mentioned about Value Field of the DropDownList1. what about the Text Field of the DropDownList1. Is it same or different??.
I guess Text fields are same. so it takes first ID .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900