Question about saving an image to SQL database
-
Okay, here is my problem: I've got a web site that allows users to edit their profile. Part of this profile information will be used to populate a contact page which will include a picture of the user. Now, I'm able to upload the pictures just fine into a sql 2005 database and display that image, but if the user doesn't add an image (which they are allow not to do) then I get stuck on how to populate that into my sql stored procedure's parameter list. I keep getting an error every time I try saving the profile without an image in the file upload box. Here is the code that I am using to try to put in a dbnull value:
cmd.Parameters.AddWithValue("@picture", SqlDbType.Image).Value = DBNull.Value
Any ideas on what I'm doing wrong?
-
Okay, here is my problem: I've got a web site that allows users to edit their profile. Part of this profile information will be used to populate a contact page which will include a picture of the user. Now, I'm able to upload the pictures just fine into a sql 2005 database and display that image, but if the user doesn't add an image (which they are allow not to do) then I get stuck on how to populate that into my sql stored procedure's parameter list. I keep getting an error every time I try saving the profile without an image in the file upload box. Here is the code that I am using to try to put in a dbnull value:
cmd.Parameters.AddWithValue("@picture", SqlDbType.Image).Value = DBNull.Value
Any ideas on what I'm doing wrong?
That doesn't look right to me. Can't you just put
cmd.Parameters.AddWithValue("@picture", DBNull.Value)
? (Assuming your "picture" field allows nulls, of course...)
-
That doesn't look right to me. Can't you just put
cmd.Parameters.AddWithValue("@picture", DBNull.Value)
? (Assuming your "picture" field allows nulls, of course...)