Command Parameters

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

    #1

    Command Parameters

    Can someone tell me why the following code does not work ?

    It does not crash or cause errors and it creates a new row in the table
    "tblusers" but the fields are NULL.

    Sub doInsert()
    'Create Insert string
    Dim MySQL As String = "Insert into tblusers (USERTEXT) values (@Pnotes)"
    'Set up connection to mysql database
    Dim myConn As OdbcConnection = New
    OdbcConnection( "driver={MySql} ;uid=root;pwd=; server=127.0.0. 1;database=dbnr g
    plc;OPTION=1792 3")
    Dim Cmd As New OdbcCommand(MyS QL, myConn)
    Cmd.Parameters. Add(New OdbcParameter(" @Pnotes", Me.txtNotes.Tex t))
    myConn.Open()
    Cmd.ExecuteNonQ uery()
    myConn.Close()
    End Sub

    Thanks in Advance


  • S. Justin Gengo

    #2
    Re: Command Parameters

    Paul,

    Run the debugger and see if the text box actually has a value in it.

    My guess is that your code is clearing the text box on post back.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche
    "Paul" <paul@themedial ounge.com> wrote in message
    news:udxTRUCXDH A.888@TK2MSFTNG P10.phx.gbl...[color=blue]
    > Can someone tell me why the following code does not work ?
    >
    > It does not crash or cause errors and it creates a new row in the table
    > "tblusers" but the fields are NULL.
    >
    > Sub doInsert()
    > 'Create Insert string
    > Dim MySQL As String = "Insert into tblusers (USERTEXT) values[/color]
    (@Pnotes)"[color=blue]
    > 'Set up connection to mysql database
    > Dim myConn As OdbcConnection = New
    >[/color]
    OdbcConnection( "driver={MySql} ;uid=root;pwd=; server=127.0.0. 1;database=dbnr g[color=blue]
    > plc;OPTION=1792 3")
    > Dim Cmd As New OdbcCommand(MyS QL, myConn)
    > Cmd.Parameters. Add(New OdbcParameter(" @Pnotes", Me.txtNotes.Tex t))
    > myConn.Open()
    > Cmd.ExecuteNonQ uery()
    > myConn.Close()
    > End Sub
    >
    > Thanks in Advance
    >
    >[/color]


    Comment

    Working...