Windows ユーザーフォームを設計しています。ここでフォームを確認できます。問題は、ほとんどのテキスト ボックスにデータが入力されていないことです。フォームの上部にあるボタンを使用して、データベースを「参照」し、レコードを追加、変更、および削除しようとしています。
DataAdapter
フォームに送信できるように、さまざまなテーブルからすべてのデータを取得するための適切な SQL クエリがないようです。適切なクエリを生成し、データをフォームに渡す方法を教えてください。データベースの構成はこちらで確認できます。誰かが私を助けることができれば、それは素晴らしいことです.
フォームのコードは以下です。
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