mysql中update成功返回null,UPDATE命令返回null :( ..为什么?

protected void GVImages_RowUpdating(object sender, GridViewUpdateEventArgs e)

{

string ID = ((Label)GVImages.Rows[e.RowIndex].FindControl("lblID")).Text;

string Name = ((TextBox)GVImages.Rows[e.RowIndex].FindControl("txtName")).Text;

FileUpload f = ((FileUpload)GVImages.Rows[e.RowIndex].FindControl("FileUpload2"));

byte[] imageBytes = null;

if (f.HasFile)

{

//variable to store the image content

imageBytes = new byte[f.PostedFile.ContentLength];

HttpPostedFile uploadImage = f.PostedFile;

//read the image stream from the post and store it in imageBytes

uploadImage.InputStream.Read(imageBytes, 0, (int)f.PostedFile.ContentLength);

}

con.Open();

MySqlCommand cmd = new MySqlCommand("Update images set Name=@Name,Content=@Content where ID="+ID, con);

cmd.Parameters.Add("@ID", MySqlDbType.Int16).Value = ID;

cmd.Parameters.Add("@Name", MySqlDbType.VarChar).Value= Name;

cmd.Parameters.Add("@Content", MySqlDbType.LongBlob).Value = imageBytes;

cmd.Connection = con;

cmd.ExecuteNonQuery();

GVImages.EditIndex = -1;

con.Close();

databind();

}

解决方案Try replaceing

MySqlCommand cmd = new MySqlCommand("Update images set Name=@Name,Content=@Content where ID=" +ID, con);

with

MySqlCommand cmd = new MySqlCommand(" Update images set Name=@Name,Content=@Content where ID=@ID", con);

Basically, ExecuteNonQuery() method should return you an integer, but you don''t catch it in any variable in your code ; you can watch its value by debugging, either.

The question you should concentrate on is : What do you want to get from an UPDATE command ?

Do you expect to get a resultset (i.e., one or more rows) ? You won''t.

If you want to get a resultset from a query, it must be a SELECT one.

So, please, we need to know what exactly you are expecting from your SQL request.

As ThePhantomMenace pointed out, you are concatenating on the ID in the string but then are adding a parameter named @ID. You need to change the SQL command text to be

"Update images set Name=@Name,Content=@Content where ID=@ID"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值