Click here to Skip to main content
15,946,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

I have FileUpLoad control and Image control. i want to insert Null value when image is not there to respective column.I've used following code,

cmd.Parameters.AddWithValue("@staff_photo", DBNull.Value);
cmd.Parameters.AddWithValue("@staff_photo", string.empty);

And these code are not working.So please reply with example
Posted
Comments
Ankit Rajput 25-Apr-11 3:11am    
Is there any exception with this code?
ks ravi 25-Apr-11 3:26am    
nvarchar is incompatible with varBinary(max)
Prerak Patel 25-Apr-11 3:21am    
DBNull should work. What is the exact error? Is staff_photo not nullable by any chance?
ks ravi 25-Apr-11 3:28am    
nvarchar is incompatible with varBinary(max)

Just Allow null in Database Schema and thats all. After that if you dont provide any value it will autometically treat as a null value.
 
Share this answer
 
Comments
ks ravi 25-Apr-11 3:30am    
den how to pass Null value or Image through Stored Proc Parameter(@staff_photo)
nvarchar is incompatible with varBinary(max)

Then try this,
cmd.Parameters.Add("@staff_photo", System.Data.SqlDbType.VarBinary).Value = DBNull.Value;


And as I said in comment, it must be nullable.
 
Share this answer
 
v2
Comments
Ponka Nemov 22-Mar-12 15:45pm    
this last solution proposed by Perak works.
define in store procedure
@staff_photo varchar(50)=null, if you are saving only photo path
 
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