i want to save my picture in database i have these codes but then there is an error . " command text was not set for the command object " how to solve this problem? thank you.!
Try
If imgName <> "" Then
Dim fs As FileStream
fs = New FileStream(imgName, FileMode.Open, FileAccess.Read)
Dim picByte As Byte() = New Byte(fs.Length - 1) {}
fs.Read(picByte, 0, System.Convert.ToInt32(fs.Length))
fs.Close()
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
cn = New OleDbConnection("Provider = Microsoft.ACE.oledb.12.0; Data Source=|DataDirectory|\EMwithPayrollSystem.accdb;Jet OLEDB:Database Password=jhedonghae;")
cn.Open()
cmd = New OleDbCommand("Select * From EmployeeProfile", con)
cmd = New OleDbCommand("UPDATE EmployeeProfile SET IDPictureLocation = '" & imgName & "' where EmployeeNumber ='" & EmployeeNumberTB.Text & "'", cn)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader
'cn.Close()
Dim imgParam As New OleDbParameter()
imgParam.OleDbType = OleDbType.Binary
imgParam.ParameterName = "Img"
imgParam.Value = picByte
Dim cmda As New OleDbCommand(strsql, cn)
cmda.Parameters.Add(imgParam)
cmda.ExecuteNonQuery()
MessageBox.Show("Image successfully saved.")
cmd.Dispose()
CN.Close()
CN.Dispose()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try