Passing Parameter value in vb.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • programmer2004

    Passing Parameter value in vb.net

    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(B yVal sender As Object, ByVal e As System.EventArg s) Handles cmdsave.Click
    Dim command As New OdbcCommand
    Dim str As String

    Dim photo() As Byte = GetPhoto(txtpat h.Text)
    str= insert into emp(id, name, photo) values (1,@name,@photo )
    command = New OdbcCommand(str , con.cn) ' con.cn is connection object
    command.Paramet ers.Add("@name" , OdbcType.VarCha r, 20).Value = "sagar"
    command.Paramet ers.Add("@photo ", OdbcType.Image, photo.Length).V alue = photo
    command.Execute NonQuery()
    msgbox "saved"
    End Sub

    Public Shared Function GetPhoto(ByVal filePath As String) As Byte()
    Dim fs As FileStream = New FileStream(file Path, 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

  • Cor Ligthert

    #2
    Re: Passing Parameter value in vb.net

    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


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Passing Parameter value in vb.net

      * "=?Utf-8?B?cHJvZ3JhbW1 lcjIwMDQ=?=" <programmer2004 @discussions.mi crosoft.com> scripsit:[color=blue]
      > I am trying to pass parameter value to ODBCCommand object.[/color]

      In addition to the other replies: There is a separate group for .NET +
      database related questions available:

      <URL:news://news.microsoft. com/microsoft.publi c.dotnet.framew ork.adonet>

      Web interface:

      <URL:http://msdn.microsoft. com/newsgroups/?dg=microsoft.p ublic.dotnet.fr amework.adonet>

      --
      Herfried K. Wagner [MVP]
      <URL:http://dotnet.mvps.org/>

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Passing Parameter value in vb.net

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

        URL:news://news.microsoft.com/microsoft....mework.odbcnet

        Web interface:

        URL:http://msdn.microsoft.com/newsgroups...mework.odbcnet

        Hope this helps
        Jay

        "programmer2004 " <programmer2004 @discussions.mi crosoft.com> wrote in message
        news:D0DFA249-C925-41F5-A61D-2E22A696EC05@mi crosoft.com...[color=blue]
        > 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[/color]
        following code,[color=blue]
        >
        > Private Sub cmdsave_Click(B yVal sender As Object, ByVal e As[/color]
        System.EventArg s) Handles cmdsave.Click[color=blue]
        > Dim command As New OdbcCommand
        > Dim str As String
        >
        > Dim photo() As Byte = GetPhoto(txtpat h.Text)
        > str= insert into emp(id, name, photo) values (1,@name,@photo )
        > command = New OdbcCommand(str , con.cn) ' con.cn is[/color]
        connection object[color=blue]
        > command.Paramet ers.Add("@name" , OdbcType.VarCha r, 20).Value = "sagar"
        > command.Paramet ers.Add("@photo ", OdbcType.Image,[/color]
        photo.Length).V alue = photo[color=blue]
        > command.Execute NonQuery()
        > msgbox "saved"
        > End Sub
        >
        > Public Shared Function GetPhoto(ByVal filePath As String) As Byte()
        > Dim fs As FileStream = New FileStream(file Path, FileMode.Open,[/color]
        FileAccess.Read )[color=blue]
        > 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
        >[/color]


        Comment

        Working...