I'm designing a windows user form. You can see the form here, the issue is that the most of the text boxes are never populated with data. I'm trying to use the buttons on the top of the form to "browse" the database and add, modify, and delete records.
I don't seem to have the right SQL query to grab all the data from the different tables to that my DataAdapter can send it to the form. I'm looking for help in generating the right query and passing data to the form. You can see the makeup of the database here. If anyone could help me out that would be awesome.
The code for the form is below.
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