I know this is a simple idea, but I am new to vb.net and using a database. My only experience with vb is VBA in excel. Here is what i am trying to do.
I have a listbox (lstName) that is populated by column 3 in my database. I have 3 textboxs that I want to display the other columns in the table when the user selects an item in the listbox. i know how to get the index of the listbox item, but how can I relate that to the row on the table. And then the textboxes with have the data from the other columns. Below is the code I use on Form_Load.
I have a listbox (lstName) that is populated by column 3 in my database. I have 3 textboxs that I want to display the other columns in the table when the user selects an item in the listbox. i know how to get the index of the listbox item, but how can I relate that to the row on the table. And then the textboxes with have the data from the other columns. Below is the code I use on Form_Load.
VB.NET:
Public Class Form1
Dim inc As Integer
Dim MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim dt As New DataSet
Dim db As New OleDb.OleDbDataAdapter
Dim sql As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MainDatabaseDataSet.SyscoM' table. You can move, or remove it, as needed.
Me.SyscoMTableAdapter.Fill(Me.MainDatabaseDataSet.SyscoM)
con.ConnectionString = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source = D:\Ben's Documents\Work Things\Cost Manangment System\MainDatabase.accdb"
con.Open()
sql = "SELECT * FROM SyscoM"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "SyscoPrice")
con.Close()
MaxRows = ds.Tables("SyscoPrice").Rows.Count
For inc As Integer = 0 To MaxRows - 1
lstName.Items.Add(ds.Tables("SyscoPrice").Rows(inc).Item(3))
Next inc
lstName.Sorted = True
inc = -1
End Sub