使用图像更新数据 [英] Updating data with image

查看:65
本文介绍了使用图像更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在使用图像更新数据时有效。但问题是,当我编辑现有的记录时,我不会更改图像。 `picturebox`变为null。



This code works when Updating data with image. However, The problem is when i edit the record that is existing and i do not change the image. The `picturebox` becomes null.

cmd.Parameters.Add(New SqlParameter("@StudPic", SqlDbType.Image)) 
If (Not String.IsNullOrEmpty(Me.Name) AndAlso System.IO.File.Exists(a.FileName)) Then 
cmd.Parameters("@StudPic").Value = System.IO.File.ReadAllBytes(a.FileName) 
Else 
cmd.Parameters("@StudPic").Value = DBNull.Value 
End If 







我试过的是这个




What i have tried is this

cmd.Parameters.Add(New SqlParameter("@StudPic", SqlDbType.Image)) 
If (Not String.IsNullOrEmpty(Me.Name) AndAlso System.IO.File.Exists(a.FileName)) Then 
cmd.Parameters("@StudPic").Value = System.IO.File.ReadAllBytes(a.FileName) 
Else 
cmd.Parameters("@StudPic").Value = System.IO.File.ReadAllBytes(a.FileName) 
End If 





但它给我一个错误。此行的空路径不合法



But it throws me an error. Empty path is not legal with this line

cmd.Parameters("@StudPic").Value = System.IO.File.ReadAllBytes(a.FileName)

`。任何人都可以帮我解决这个问题。提前谢谢

` . Can anyone help me to fix this. thanks in advance

推荐答案

我建​​议您检查存储过程中的参数值。如果 null ,则不要更新。
I would suggest you to check the parameter value in Stored Procedure. If it is null, then don't update.


这篇关于使用图像更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆