Good Day, i develop a program is one time insert 2 picture 2 database code below is my code. i face the error message is Data type mismatch in criteria expression. can some one guide me
cmd.Parameters.Clear()
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
If PictureBox1.Image IsNot Nothing Or picPath IsNot Nothing Then
If PictureBox1.Image Is Nothing Then
cmd.CommandText = "insert into Table1(picture,F1, F2, F3,Picture1)" &
" values (@picture,@F1, @F2, @F3,@picture1)"
Dim parameter2 = cmd.Parameters.Add("@picture", CType(SqlDbType.VarBinary, OleDbType), -1)
If PictureBox1.ImageLocation Is Nothing Then
parameter2.Value = DBNull.Value
Else
parameter2.Value = File.ReadAllBytes(PictureBox1.ImageLocation)
End If
Dim DataPic_Update As Byte() = ImageToBytes(Image.FromFile(picPath), ImageFormat.Png)
cmd.Parameters.AddWithValue("@picture1", DataPic_Update)
ElseIf picPath Is Nothing Then
cmd.CommandText = "insert into Table1(Picture, F1, F2, F3)" &
" values (@picture, @F1, @F2, @F3)"
Dim DataPic_Update As Byte() = ImageToBytes(PictureBox1.Image, ImageFormat.Png)
cmd.Parameters.AddWithValue("@picture", DataPic_Update)
Else
cmd.CommandText = "insert into Table1(Picture, F1, F2, F3,Picture1)" &
" values (@picture, @F1, @F2, @F3,@picture1)"
Dim DataPic_Update As Byte() = ImageToBytes(Image.FromFile(picPath), ImageFormat.Png)
cmd.Parameters.AddWithValue("@picture1", DataPic_Update)
cmd.Parameters.AddWithValue("@picture", DataPic_Update)
End If
Else
cmd.CommandText = "insert into Table1(F1, F2, F3)" &
"values (@F1, @F2, @F3)"
End If
cmd.Parameters.AddWithValue("@F1", Me.TextBox1.Text)
cmd.Parameters.AddWithValue("@F2", Me.TextBox2.Text)
cmd.Parameters.AddWithValue("@F3", Me.TextBox3.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("Record Is Added")
RefreshData()
End Sub