Click here to Skip to main content
15,665,229 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
scmd1.CommandText = "SELECT User_Comments FROM Add_Comment WHERE Id='" + Dbid + "'";

                    scmd1.Connection = conn2;

                    //sql datareader
                    SqlDataReader sqldread2 = scmd1.ExecuteReader();
                    UserComment.Text = (sqldread2["User_Comments"].ToString());

i have datatable for user comment?
there are multiple comments to a particular id...

so i want to get all the comments into textbox?

how can i get it?

this code gives me an error in my select query

Object reference not set to an instance of an object.
Updated 26-Jul-13 15:51pm
Sergey Alexandrovich Kryukov 26-Jul-13 21:40pm    
In what line?
Where can we see that conn2 is not null, for example?
[no name] 26-Jul-13 21:41pm    
And again, you have to call the Read method on a SqlDataReader before you can get any data out of it.
Sergey Alexandrovich Kryukov 26-Jul-13 21:43pm    
[no name] 26-Jul-13 21:48pm    
Only the 6th time I have told him that.
Sergey Alexandrovich Kryukov 26-Jul-13 21:56pm    
Sixth?! No kidding?! Maybe this is a call for the abuse report on the account, not just particular question, as it apparently does not take desired effect.

1 solution

0) Use a parameterized command
1) Don't use strings for IDs
2) Is the connection open?
3) Read from the reader in a loop
4) I assume the value (when you get one) is already a string, so don't use ToString
5) Append the values to the TextBox

6) Put the DataReader in a using statement (the command too, if you like)
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