Reputation: 6778
I cant figure out why the update query below doesn't executes, any suggestions:
static public void updateSelectedMainNewsImage(int newsID, string filename, string replace)
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand updateNews = new SqlCommand("Update newsImages SET [newsImage] =@filename where [newsID] =@newsID AND [newsImage] =@replace", conn);
updateNews.Parameters.AddWithValue("@newsID",SqlDbType.Int).Value = newsID;
updateNews.Parameters.AddWithValue("@filename",SqlDbType.VarChar).Value = filename;
updateNews.Parameters.AddWithValue("@replace",SqlDbType.VarChar).Value = replace;
updateNews.ExecuteNonQuery();
conn.Close();
}
Upvotes: 0
Views: 95
Reputation: 6486
you are using updateNews.Parameters.AddWithValue("@filename",SqlDbType.VarChar).Value = filename;
try to replace this with
updateNews.Parameters.AddWithValue("@filename",filename,SqlDbType.VarChar);
it's because parameter.addwithvalue function does not need value property be set it has an overloaded version like above.i hope if this can help
Upvotes: 1
Reputation: 51200
If it's not erroring then it IS working. None of the records are meeting your WHERE conditions.
Upvotes: 2