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();
   }

try two things.
first: try to make the id parameter in the same manner as the others.
second: instead of using the ExecuteReader method use ExecuteNonQuery method. that returns the number of rows affected by the query.

regards.

"second" did the trick :) Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.