stevennathaniel

ODBC DataReader Berhasil Membaca Mysql

Nov 30th, 2015
126
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data.Odbc
  2.  
  3.  
  4. Public Class Form7
  5.  
  6.     Dim koneksi As OdbcConnection = Nothing
  7.  
  8.     Dim stringKoneksi As String = "DSN=localhost"
  9.  
  10.     Dim stringSQL As String
  11.  
  12.  
  13.  
  14.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  15.  
  16.         koneksi = New OdbcConnection(stringKoneksi)
  17.  
  18.         stringSQL = "SELECT * FROM tanggal"
  19.  
  20.         Dim perintah As New OdbcCommand(stringSQL, koneksi)
  21.  
  22.         Try
  23.  
  24.             koneksi.Open()
  25.  
  26.             Dim baca As OdbcDataReader = perintah.ExecuteReader
  27.  
  28.             While baca.Read()
  29.  
  30.                 MessageBox.Show("idtanggal" & " " & baca(1).ToString())
  31.  
  32.             End While
  33.  
  34.             baca.Close()
  35.  
  36.             koneksi.Close()
  37.  
  38.  
  39.         Catch ex As Exception
  40.  
  41.             MessageBox.Show(ex.Message)
  42.  
  43.         End Try
  44.  
  45.  
  46.     End Sub
  47. End Class
RAW Paste Data