I would like to get data from my database to my label.
This is my code:
con = new SqlConnection(conS);
try
{
con.Open();
string q = "SELECT SearchTerm FROM Sentiment WHERE Sentiment = 'positive'";
SqlCommand query = new SqlCommand(q, con);
using (SqlDataReader dr = query.ExecuteReader())
{
bool success = dr.Read();
if (success)
{
// Label1.Text = dr.GetString(1);
label3.Text = dr.GetString(1);
}
}
con.Close();
}
catch (Exception ex)
{
label3.Text = "Error";
}
However when I run the application, my label is showing 'Error'. What is wrong with this code?
Thank you in advance :)