stevennathaniel

Simpan ODBC Prepared Statement MYSQL

Nov 29th, 2015
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data.Odbc
  2.  
  3. Public Class Form4
  4.  
  5.     Dim koneksi As OdbcConnection = Nothing
  6.  
  7.     Dim stringKoneksi As String = "DSN=localhost"
  8.  
  9.     Dim stringSQL As String
  10.  
  11.  
  12.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  13.  
  14.         koneksi = New OdbcConnection(stringKoneksi)
  15.  
  16.         stringSQL = "INSERT INTO nama(idnama,namapegawai) VALUES(?,?)"
  17.  
  18.         Try
  19.  
  20.             koneksi.Open()
  21.  
  22.             Dim perintah = New OdbcCommand(stringSQL, koneksi)
  23.  
  24.             perintah.Prepare()
  25.  
  26.             perintah.Parameters.AddWithValue("@idnama", TextBox1.Text)
  27.  
  28.             perintah.Parameters.AddWithValue("@namapegawai", TextBox2.Text)
  29.  
  30.             perintah.ExecuteNonQuery()
  31.  
  32.             koneksi.Close()
  33.  
  34.  
  35.         Catch ex As Exception
  36.  
  37.             MessageBox.Show(ex.Message)
  38.  
  39.         End Try
  40.  
  41.         TextBox1.Text = ""
  42.         TextBox2.Text = ""
  43.  
  44.     End Sub
RAW Paste Data