Saafia NM

Saafia NM

  • NA
  • 52
  • 11.2k

Select Query is not working

Feb 29 2016 6:47 AM
Table Name:Index 
 ID Keyword
 123,345,567 Test
 
I tried to get the ID values in a TextBox2 using following Code while entering the Keyword in TextBox1:
 
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString()); 
 
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select ID from Index where Keyword=@keyword",con);
cmd.Parameters.AddWithValue("@keyword",TextBox1.Text);
con.Open();
SqlDataReader dt = cmd.ExecuteReader();
if (dt.Read())
{
TextBox2.Text = dt.ToString();
}
 
But i got the result as
 
"System.Data.SqlClient.SqlDataReader"  in the TextBox2 ; what is the problem in my code???
 

Answers (7)