我正在設計一個windows用戶窗體。您可以看到表格here,問題是絕大多數文本框永遠不會填充數據。我試圖使用表單頂部的按鈕來「瀏覽」數據庫並添加,修改和刪除記錄。多表的綁定按鈕
我似乎沒有正確的SQL查詢來抓取不同表格中的所有數據,我的DataAdapter
可以將它發送到表單。我正在尋找幫助來生成正確的查詢並將數據傳遞給表單。你可以看到數據庫的構成here。如果任何人都可以幫助我,那就太棒了。
該表單的代碼如下。
Imports System.Data.OleDb
Public Class DeviceEditorForm
Dim tabletDataAdapter As OleDbDataAdapter
Dim tabletDataSet As DataSet
Private Sub DeviceEditorForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.DeviceTableAdapter.Fill(Me.BIT_3444_DatabaseDataSet.Device)
Dim sqlStatement As String = "select * from Device"
Dim tabletConnectionStr As String = "provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\BIT 3444 Database.accdb"
tabletDataAdapter = New OleDbDataAdapter(sqlStatement, tabletConnectionStr)
tabletDataSet = New DataSet
tabletDataAdapter.Fill(tabletDataSet, "Device")
DeviceBindingSource.DataSource = tabletDataSet.Tables(0)
BindingNavigator1.BindingSource = DeviceBindingSource
Dim batterySizeBinding As New Binding("text", DeviceBindingSource, "Battery_Size")
BatterySizeTextBox.DataBindings.Add(batterySizeBinding)
Dim IDBinding As New Binding("text", DeviceBindingSource, "ID")
DeviceIdTextBox.DataBindings.Add(IDBinding)
Dim nameBinding As New Binding("text", DeviceBindingSource, "Device_Name")
DeviceNameTextBox.DataBindings.Add(nameBinding)
Dim manufacturerBinding As New Binding("text", DeviceBindingSource, "Manufacturer")
ManufacturerTextBox.DataBindings.Add(manufacturerBinding)
Dim modelYearBinding As New Binding("text", DeviceBindingSource, "Model_Year")
ModelYearTextBox.DataBindings.Add(modelYearBinding)
Dim osBinding As New Binding("text", DeviceBindingSource, "Operating_System")
OperatingSystemTextBox.DataBindings.Add(osBinding)
Dim osVersionBinding As New Binding("text", DeviceBindingSource, "Operating_System_Version")
OsVersionTextBox.DataBindings.Add(osVersionBinding)
Dim priceBinding As New Binding("text", DeviceBindingSource, "Price")
PriceTextBox.DataBindings.Add(priceBinding)
End Sub
Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click
DeviceBindingSource.EndEdit()
Dim tabletCommandBuilder As New OleDbCommandBuilder(tabletDataAdapter)
tabletDataAdapter.InsertCommand = tabletCommandBuilder.GetInsertCommand()
tabletDataAdapter.DeleteCommand = tabletCommandBuilder.GetDeleteCommand()
tabletDataAdapter.UpdateCommand = tabletCommandBuilder.GetUpdateCommand()
Dim numOfRecords As Integer = tabletDataAdapter.Update(tabletDataSet, "Device")
MsgBox(numOfRecords & " records have been updated.")
End Sub
End Class
謝謝我承諾你推薦的更改,但現在我的綁定添加項目和刪除按鈕不起作用我收到一個SQL錯誤 – Matt 2013-04-29 01:07:08