Passing Parameter value in vb.net

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
 
C

Cor Ligthert

Hi Programmer,

I would not use ODBC in dotNet anymore, use when you are able to SQLclient
and when not OleDB.

ODBC gives mostly a lot of troubles and after a while the one who tried goes
to OleDb.

And have a look at the dataset, however the links I gave you in your message
above will probably help you. (Take a look at the dataset).

Cor
 
J

Jay B. Harlow [MVP - Outlook]

programmer2004,
In addition to the ADO.NET newsgroup that Herfried identified, you may try
the microsoft.public.dotnet.framework.odbcnet newsgroup as it deals
specifically with ODBC in ADO.NET issues...

URL:news://news.microsoft.com/microsoft.public.dotnet.framework.odbcnet

Web interface:

URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framework.odbcnet

Hope this helps
Jay

programmer2004 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top