Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Const database_file As String = "C:\Database.mdb"
Dim strConnection As String = "provider=microsoft.Jet.Oledb.4.0;" & _
"Data Source=" & database_file
Dim conn As New OleDbConnection(strConnection)
Dim cmd As New OleDbCommand
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim Cbb1 As String
Dim Ckb1 As String, Ckb2 As String, Ckb3 As String
Dim dr As String
Private Sub Bindings()
'*** DataTable ***'
Dim dt As New DataTable
Dim sel As String = "SELECT * FROM Ticket"
Dim cm As New OleDbCommand(sel, conn)
conn.Open()
cm.ExecuteNonQuery()
sit1.DataBindings.Add("Text", ds, "sit3")
conn.Close()
'Binding ข้อมูลกับ TextBox
End Sub
Private Sub frmEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myConnection As SqlCeConnection
Dim dt As New DataTable
Dim Adapter As SqlCeDataAdapter
'myConnection = New SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ) + "\Database1.sdf;"))
myConnection = New SqlCeConnection("Data Source=C:\WindowsFormsApplication\WindowsFormsApplication\Database1.sdf;")
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = "SELECT [id], [name], [email] FROM [mytable] WHERE id = '" & strID & "' "
myCommand.CommandType = CommandType.Text
Adapter = New SqlCeDataAdapter(myCommand)
Adapter.Fill(dt)
myConnection.Close()
If dt.Rows.Count > 0 Then
Me.txtName.Text = dt.Rows(0)("name")
Me.txtEmail.Text = dt.Rows(0)("email")
End If
dt = Nothing
End Sub