I have this code that works fine:
protected void ButtonImgTextToDB_Click(object sender, EventArgs e)
{
string ID = TextBoxStartPictID.Text;
string Rubrik = TextBoxHeadLineStart.Text;
string Text = TextBoxTextStart.Text;
SqlConnection conn = new SqlConnection(config);
conn.Open();
string sql = "UPDATE StartImage SET Headline ='" + Rubrik +
"', Text ='" + Text + "' WHERE ID ='" + ID + "'";
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader dr = comm.ExecuteReader();
//messagebox
//clear textboxes
conn.Close();
}
And then I have this code that I'd rather use, with parameters, for the exact same function. This code does not work (no error message, it's just that it does nothing). How is that?:
protected void ButtonImgTextToDB_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(config);
conn.Open();
string sql = "UPDATE StartImage SET Headline = @Headline,
Text= @Text WHERE ID ='" + ID + "'";
SqlCommand comm = new SqlCommand(sql, conn);
SqlParameter param1 = new SqlParameter("@Headline",
SqlDbType.VarChar, 50);
param1.Value = TextBoxHeadLineStart.Text;
comm.Parameters.Add(param1);
SqlParameter param2 = new SqlParameter("@Text", SqlDbType.VarChar, 300);
param2.Value = TextBoxTextStart.Text;
comm.Parameters.Add(param2);
//messagebox
//clear textboxes
comm.ExecuteReader();
conn.Close();
}