V
VB Novice Hendri
Guest
Pleas help, this will seem simple to a lot of you, I done a lot of reading but stil don't get it.
I have a Access DataBase "Recipes DataBase.laccdb" located in a Folder in My Documents.
This DataBase has 8 Tabels "Main Dishes", "Desserts" and so on.
Each of this Tabels has 56 Colums "ID" = Primery Key, "Recipe Name", "Caption","Delivery", "Con 1" to "Con 50", "Comment", "Category".
On my Form I have a ListBox that must at first be populated with the Titles of the Tabels, once a selection is made all the Recipe Names in that Table must be desplayed, at the same time all Colum names from "Recipe Name" to "Category" must show in TextBoxes that is on th Form.
I got this code that I thought will be easy to adaped, but now I gust dont get it.
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Namespace Classes
Public Class DataOperationsAccess
Private ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=NorthWind.accdb"
Public LastException As Exception
Public Function LoadCustomerRecordsUsingDataTable() As DataTable
Dim selectStatement =
"SELECT Cust.Recipes DataBase , CT.Main Dishes, Cust.ID, " &
"Cust.Recipe Name, Cust.Caption, Cust.Delivery, " &
"Cust.Con 1, Cust.Con 2, Cust.Con 3, Cust.Con 4 " &
"Cust.Con 4, Cust.Con 5, Cust.Con 6, Cust.Con 7 " &
"Cust.Con 8, Cust.Con 9, Cust.Con 10, " &
"FROM Customers AS Cust INNER JOIN ContactType AS CT ON " &
"Cust.ContactTypeIdentifier = CT.ContactTypeIdentifier;"
Dim customerDataTable = New DataTable
Using cn As New OleDbConnection With {.ConnectionString = ConnectionString}
Using cmd As New OleDbCommand With {.Connection = cn}
Try
cmd.CommandText = selectStatement
cn.Open()
customerDataTable.Load(cmd.ExecuteReader())
customerDataTable.Columns("CustomerIdentifier").ColumnMapping = MappingType.Hidden
customerDataTable.Columns("ContactTypeIdentifier").ColumnMapping = MappingType.Hidden
customerDataTable.Columns("ModifiedDate").ColumnMapping = MappingType.Hidden
Catch ex As Exception
LastException = ex
End Try
End Using
End Using
Return customerDataTable
End Function
End Class
End Namespace
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connection As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\redgabanan\Desktop\Gabanan_Red_dbaseCon\Red_Database.accdb")
connection.Open()
Dim reader As OleDbDataReader = Nothing
Dim command As OleDbCommand = New OleDbCommand("SELECT * from Users WHERE LastName='" & TextBox1.Text & "'", connection)
reader = command.ExecuteReader()
ListBox1.Items.Clear()
While reader.Read()
ListBox1.Items.Add(reader(1).ToString() & "," + reader(2).ToString())
End While
connection.Close()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
End Class
Continue reading...
I have a Access DataBase "Recipes DataBase.laccdb" located in a Folder in My Documents.
This DataBase has 8 Tabels "Main Dishes", "Desserts" and so on.
Each of this Tabels has 56 Colums "ID" = Primery Key, "Recipe Name", "Caption","Delivery", "Con 1" to "Con 50", "Comment", "Category".
On my Form I have a ListBox that must at first be populated with the Titles of the Tabels, once a selection is made all the Recipe Names in that Table must be desplayed, at the same time all Colum names from "Recipe Name" to "Category" must show in TextBoxes that is on th Form.
I got this code that I thought will be easy to adaped, but now I gust dont get it.
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Namespace Classes
Public Class DataOperationsAccess
Private ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=NorthWind.accdb"
Public LastException As Exception
Public Function LoadCustomerRecordsUsingDataTable() As DataTable
Dim selectStatement =
"SELECT Cust.Recipes DataBase , CT.Main Dishes, Cust.ID, " &
"Cust.Recipe Name, Cust.Caption, Cust.Delivery, " &
"Cust.Con 1, Cust.Con 2, Cust.Con 3, Cust.Con 4 " &
"Cust.Con 4, Cust.Con 5, Cust.Con 6, Cust.Con 7 " &
"Cust.Con 8, Cust.Con 9, Cust.Con 10, " &
"FROM Customers AS Cust INNER JOIN ContactType AS CT ON " &
"Cust.ContactTypeIdentifier = CT.ContactTypeIdentifier;"
Dim customerDataTable = New DataTable
Using cn As New OleDbConnection With {.ConnectionString = ConnectionString}
Using cmd As New OleDbCommand With {.Connection = cn}
Try
cmd.CommandText = selectStatement
cn.Open()
customerDataTable.Load(cmd.ExecuteReader())
customerDataTable.Columns("CustomerIdentifier").ColumnMapping = MappingType.Hidden
customerDataTable.Columns("ContactTypeIdentifier").ColumnMapping = MappingType.Hidden
customerDataTable.Columns("ModifiedDate").ColumnMapping = MappingType.Hidden
Catch ex As Exception
LastException = ex
End Try
End Using
End Using
Return customerDataTable
End Function
End Class
End Namespace
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connection As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\redgabanan\Desktop\Gabanan_Red_dbaseCon\Red_Database.accdb")
connection.Open()
Dim reader As OleDbDataReader = Nothing
Dim command As OleDbCommand = New OleDbCommand("SELECT * from Users WHERE LastName='" & TextBox1.Text & "'", connection)
reader = command.ExecuteReader()
ListBox1.Items.Clear()
While reader.Read()
ListBox1.Items.Add(reader(1).ToString() & "," + reader(2).ToString())
End While
connection.Close()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
End Class
Continue reading...