Public Class openn ' create open db
Public Sub connectData()
Dim conn As New OleDbConnection
Dim s As String
If conn.State = ConnectionState.Open Then
conn.Close()
End If
s = "Provider=Microsoft.Jet.OLEDB.4.0;"
s = s + "Data Source=c:\testvb\testvb1\inven.mdb;"
conn.ConnectionString = s
conn.Open()
ss = conn.State
If conn.State = ConnectionState.Open Then
MessageBox.Show("ok_ja")
End If
End Sub
End Class
Code (VB.NET)ส่วนเรียกใช้ Class
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a As New openn
a.connectData() ' open DB
Dim txt1 As String = TextBox1.Text
Dim Data1 = New DataSet()
' start sql
Dim sql As String = "SELECT * From tb_hardware where confirm='ยืนยัน'"
Dim runn As New OleDbCommand(sql,????)
Dim adap = New OleDbDataAdapter(runn)
adap.Fill(Data1, "center_code")
' DataGridView1.
DataGridView1.DataSource = Data1.Tables("center_code")
End Sub