Photo not saving in database

callraheel

Well-known member
Joined
Dec 12, 2004
Messages
65
Location
London,UK
Programming Experience
1-3
' getphoto will return the array of bytes of images

Dim photo() As Byte = GetPhoto()
myCommand.CommandText = "INSERT INTO photos(PhotoID,PhotoSize,Photo) VALUES(@PhotoID,@PhotoSize,@Photo);"

myCommand.Parameters.Add("@PhotoID", MySqlDbType.VarChar).Value = txtSID.Text

myCommand.Parameters.Add("@PhotoSize", MySqlDbType.Double).Value = _GetPhotoLength()

myCommand.Parameters.Add("@Photo", MySqlDbType.LongBlob).Value = photo

myCommand.ExecuteNonQuery()

And the error is as follows
MySql.Data.MySqlClient.MySqlException: #23000Column 'PhotoID' cannot be null


The procedure of adding photo like this is found in .NET Framework 1.1 documentation and in an example.

Anyhelp will be appreciated
Regards

 
However, you have dbNull field or you wouldn't get the error ... do you have a try catch statement there?

Cheers ;)

Added: Actually i think you should change the way how you add the parameters .... give it a try to add parameters as it follows:

VB.NET:
 myCommand.Parameters.Add("?PhotoID", txtSID.Text)

don't use "@" for mySQL's parameters
 
Last edited:
Well kulrom, problem was parameters, semicolon has not any problem. if used then its good otherwise no problem.

So i used the all parameteras followed by (?) and problem solved.
Well Great Work!
Cheers....
 
Back
Top