PDA

Click to See Complete Forum and Search --> : Getting a string from an SQL database


SLH
Apr 6th, 2005, 07:20 AM
I want to pull some data from an SQL database, so that i can display it in on a literal control (which has a 'text' member).

I'm not sure how to do this, because i'm getting stuck with the SQLDataReader.

Any help would be greatly appreciated.

SLH
Apr 6th, 2005, 08:31 AM
Done it i was missing the Read() method call. :rolleyes:

void SetNickName(int IDNumber, Literal DestLiteral)
{
SqlConnection myConnection = new SqlConnection("server=GEORGE;database=MyDB;Trusted_Connection=yes");
SqlCommand myCommand = new SqlCommand("select NickName from people where id=" + IDNumber, myConnection);
myConnection.Open();
SqlDataReader dr = myCommand.ExecuteReader();
dr.Read();
DestLiteral.Text = dr.GetString(0);
myConnection.Close();
}Using the nchar SQL field type.