Imports System.Data
Imports System.Data.OleDb
Public Class Form7
Dim Conn As New OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim dvm As DataViewManager
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn As String
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\TC01.accdb;Persist Security Info=False"
With Conn
If .State = ConnectionState.Open Then
.Close()
.ConnectionString = strConn
.Open()
End If
End With
Dim sqlcustomers As String
sqlcustomers = " select * from customers "
da = New OleDbDataAdapter(sqlcustomers, Conn)
da.Fill(ds, "customer")
dvm = ds.DefaultViewManager
cbo.DataSource = dvm
cbo.DisplayMember = "customers.ID"
TextBox1.DataBindings.Add("text", dvm, "customers.name")
TextBox2.DataBindings.Add("text", dvm, "customers.Address")
TextBox3.DataBindings.Add("text", dvm, "customers.tel")
Form2.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
End Class
พอรันแล้วตรงส่วนบรรทัดที่24 da.Fill(ds, "customer")
มันก็ขึ้นเหลืองแล้วแจ้งว่า The ConnectionString property has not been initialized.
ผมไม่เข้าใจว่ามันคืออะไรแล้วทำไมไม่ผ่านอ่าครับ
ส่วนตัวโปรแกรมที่ทำคือแสดงฐานข้อมูลลูกค้า ในรูปแบบ Simple Binding(ตามหัวข้อในหนังสืออะครับ)
ตามนี้เลยคับ ลองเอาไปปรับเปลี่ยนดูคับ -*- Code (VB.NET) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadFiledata()
End Sub
Private Sub LoadFiledata()
Dim strConn As String
Dim Conn As New OleDbConnection
Dim da As OleDbDataAdapter
Dim ds, dataset As New DataSet()
Dim Conn As New OleDbConnection(strConn)
Conn.Open()
Dim Sql As String = "select * from CompterTitle"
Dim Cmd As New OleDbCommand(Sql, Conn)
Dim Adapter As New OleDbDataAdapter(Cmd)
Dim Data As New DataSet()
Adapter.Fill(Data, "cat")
Dim Data1 As New DataSet()
DataGridView1.DataSource = Data.Tables("cat")
Conn.Close()
Dim sqlCategories As String
sqlCategories = "SELECT * from CompterTitle"
da = New OleDbDataAdapter(sqlCategories, Conn)
da.Fill(ds, "CompterTitle")
Return
End Sub