G
Guest
Hi,
I am trying to pass parameter value to ODBCCommand object.
but it is not assigning values , the null value is gets stored. i m using following code,
Private Sub cmdsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdsave.Click
Dim command As New OdbcCommand
Dim str As String
Dim photo() As Byte = GetPhoto(txtpath.Text)
str= insert into emp(id, name, photo) values (1,@name,@photo)
command = New OdbcCommand(str, con.cn) ' con.cn is connection object
command.Parameters.Add("@name", OdbcType.VarChar, 20).Value = "sagar"
command.Parameters.Add("@photo", OdbcType.Image, photo.Length).Value = photo
command.ExecuteNonQuery()
msgbox "saved"
End Sub
Public Shared Function GetPhoto(ByVal filePath As String) As Byte()
Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
Dim photo As Byte() = br.ReadBytes(fs.Length)
br.Close()
fs.Close()
Return photo
End Function
Please can anyone help me?
Regards
Programmer2004
I am trying to pass parameter value to ODBCCommand object.
but it is not assigning values , the null value is gets stored. i m using following code,
Private Sub cmdsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdsave.Click
Dim command As New OdbcCommand
Dim str As String
Dim photo() As Byte = GetPhoto(txtpath.Text)
str= insert into emp(id, name, photo) values (1,@name,@photo)
command = New OdbcCommand(str, con.cn) ' con.cn is connection object
command.Parameters.Add("@name", OdbcType.VarChar, 20).Value = "sagar"
command.Parameters.Add("@photo", OdbcType.Image, photo.Length).Value = photo
command.ExecuteNonQuery()
msgbox "saved"
End Sub
Public Shared Function GetPhoto(ByVal filePath As String) As Byte()
Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
Dim photo As Byte() = br.ReadBytes(fs.Length)
br.Close()
fs.Close()
Return photo
End Function
Please can anyone help me?
Regards
Programmer2004