Click here to Skip to main content
15,886,760 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

VB
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
VB
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
VB
cmd.Parameters("@StudPic").Value = System.IO.File.ReadAllBytes(a.FileName)
` . Can anyone help me to fix this. thanks in advance
Posted
Updated 2-Jan-16 18:58pm
v2

1 solution

I would suggest you to check the parameter value in Stored Procedure. If it is null, then don't update.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900