Fast decision:
I believe you need single quotes in selectStr:
string selectStr =
"SELECT name, castNotes, triviaNotes FROM tableName WHERE name = '" + show + "'";
Additional Information:
In .NET, you'll want to make sure that you explicitly close any connections when you no longer need them. The easiest way to do this is to wrap statements usingaround any types that implement IDisposable, for example, SqlConnectionin this case:
using(SqlConnection conn = new SqlConnection(connectionStr))
{
SqlDataAdapter da = new SqlDataAdapter(selectStr, conn);
DataSet ds = new DataSet();
da.Fill(ds, "tableName");
DataTable dt = ds.Tables["tableName"];
DataRow theShow = dt.Rows[0];
string response = "Name: " + theShow["name"].ToString() + "Cast: " + theShow["castNotes"].ToString() + " Trivia: " + theShow["triviaNotes"].ToString();
return response;
}
Also, it looks like your code could easily be subject to SQL injection. What if someone submits a form with the value fake name' OR 1=1;DROP DATABASE someDbName;--:?
You will want to use SQL parameters, for example:
SqlCommand cmd = new SqlCommand(
"SELECT name, castNotes, triviaNotes FROM tableName WHERE name = @show", conn);
cmd.Parameters.AddWithValue("@show", show);