Parameters MySql and VB.Net

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

    Parameters MySql and VB.Net

    Wondering if someone could help me with adding parameters to a mysql query with vb.net

    Here's my code:

    mycmd = New MySqlCommand
    'mycmd.Paramete rs.Add("?result ", MySqlType.Text)
    mycmd.Parameter s(0).Value = "This is a test"
    mycmd.Parameter s(0).Direction = ParameterDirect ion.Input
    mycmd.CommandTe xt = "Insert into result_holder(r esult_id, result) Values('45',?re sult)"
    mycmd.Connectio n = mycon
    'Try
    mycon.Open()
    mycmd.ExecuteNo nQuery()
    mycon.Close()
    Catch ex As Exception
    MsgBox(ex.Messa ge)
    End Try

    I the exception I get is "You have an error in your sql statement near 'result'

    What am I doing wrong??

    Thanks!

    Daniel



    --
    --------------------------------- --- -- -
    Posted with NewsLeecher v3.9 Final
    Web @ http://www.newsleecher.com/?usenet
    ------------------- ----- ---- -- -

  • SuNcO

    #2
    Re: Parameters MySql and VB.Net

    What do you want to do with "?result" ?

    Maybe you want to send a variable ? Then is like this :

    mycmd.CommandTe xt = "Insert into result_holder (result_id, result) Values
    ('45'," & result & ")"

    --
    Windows Live Butterfly
    My little blog - http://sunco.codigoplus.com (in Spanish)

    "Daniel" <dan@theman.com escribió en el mensaje de
    noticias:489e42 8f$0$26127$9a6e 19ea@news.newsh osting.com...
    Wondering if someone could help me with adding parameters to a mysql query
    with vb.net
    >
    Here's my code:
    >
    mycmd = New MySqlCommand
    'mycmd.Paramete rs.Add("?result ", MySqlType.Text)
    mycmd.Parameter s(0).Value = "This is a test"
    mycmd.Parameter s(0).Direction = ParameterDirect ion.Input
    mycmd.CommandTe xt = "Insert into result_holder(r esult_id, result)
    Values('45',?re sult)"
    mycmd.Connectio n = mycon
    'Try
    mycon.Open()
    mycmd.ExecuteNo nQuery()
    mycon.Close()
    Catch ex As Exception
    MsgBox(ex.Messa ge)
    End Try
    >
    I the exception I get is "You have an error in your sql statement near
    'result'
    >
    What am I doing wrong??
    >
    Thanks!
    >
    Daniel
    >
    >
    >
    --
    --------------------------------- --- -- -
    Posted with NewsLeecher v3.9 Final
    Web @ http://www.newsleecher.com/?usenet
    ------------------- ----- ---- -- -
    >

    Comment

    • Jack Jackson

      #3
      Re: Parameters MySql and VB.Net

      On 10 Aug 2008 01:21:20 GMT, Daniel <dan@theman.com wrote:
      >Wondering if someone could help me with adding parameters to a mysql query with vb.net
      >
      >Here's my code:
      >
      >mycmd = New MySqlCommand
      >'mycmd.Paramet ers.Add("?resul t", MySqlType.Text)
      >mycmd.Paramete rs(0).Value = "This is a test"
      >mycmd.Paramete rs(0).Direction = ParameterDirect ion.Input
      >mycmd.CommandT ext = "Insert into result_holder(r esult_id, result) Values('45',?re sult)"
      >mycmd.Connecti on = mycon
      >'Try
      >mycon.Open()
      >mycmd.ExecuteN onQuery()
      mycon.Close()
      >Catch ex As Exception
      >MsgBox(ex.Mess age)
      >End Try
      >
      >I the exception I get is "You have an error in your sql statement near 'result'
      >
      >What am I doing wrong??
      >
      >Thanks!
      >
      >Daniel
      I have never used MySql, but this link
      <http://dev.mysql.com/doc/refman/5.0/en/connector-net-using-prepared.html>
      uses @ instead of ? to mark parameters.

      Comment

      • Daniel

        #4
        Re: Parameters MySql and VB.Net

        That did it!! Thanks!!


        --
        --------------------------------- --- -- -
        Posted with NewsLeecher v3.9 Final
        Web @ http://www.newsleecher.com/?usenet
        ------------------- ----- ---- -- -

        Comment

        Working...