Monday, September 15, 2014

vb.net (insert into table with store procedure)

Public Class Form1
    Public conn As OdbcConnection
    Public comm As OdbcCommand
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        conn = New OdbcConnection("dsn=test;uid=root")
        conn.Open()
        'Add the call to the stored procedure including the connection
        Dim cmd As New Odbc.OdbcCommand("{ CALL sp_insertuser2(?,?) }", conn)
        cmd.CommandType = CommandType.StoredProcedure
        'add the parameter to the stored procedure
        Me.TextBox1.Text = CInt(10)
        Me.TextBox2.Text = 2
        Dim IDP As OdbcParameter = cmd.Parameters.Add("@ID", OdbcType.Int)
        Dim NameP As OdbcParameter = cmd.Parameters.Add("@Name", OdbcType.Text)
        IDP.Value = 3
        NameP.Value = "ratana 3"
        cmd.ExecuteNonQuery()
        Conn.Close()
        Conn.Dispose()
    End Sub
End Class

No comments:

Post a Comment