更新查询的问题
我不明白为什么下面的更新查询不执行,任何建议:
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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有错误,那么它正在工作。没有记录满足您的 WHERE 条件。
If it's not erroring then it IS working. None of the records are meeting your WHERE conditions.
您正在使用
updateNews.Parameters.AddWithValue("@filename",SqlDbType.VarChar).Value = filename;
尝试将其替换为
updateNews.Parameters.AddWithValue("@filename",filename ,SqlDbType.VarChar);
这是因为parameter.addwithvalue函数不需要设置value属性,它有一个像上面这样的重载版本。我希望这是否可以 帮助
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