I'm trying to display the SQL query result in a label but it's not showing. This is my code:
string result = "SELECT ACTIVE FROM [dbo].[test] WHERE ID = '" + ID.Text + "' ";
SqlCommand showresult = new SqlCommand(result, conn);
conn.Open();
showresult.ExecuteNonQuery();
string actresult = ((string)showresult.ExecuteScalar());
ResultLabel.Text = actresult;
conn.Close();
Need help please. Thanks!
This will dispose the connection and has no string concatenation in the query.
Is there a typo in there? You have two calls to the database:
This won't return a value and I'm not sure why you would have it there
Unless you have a shresult variable, this query should error. What is the shresult variable?
Use
SqlParameter
to filter the result and callExecuteScalar()
orExecuteReader()
method.Try this one.