qadeer37
Well-known member
Public Class Form1
Public Sub MakeConnection()
Dim sConnection As String
Dim dbConn As db.OleDb.OleDbConnection
sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\QADEER\Documents\Customer.accdb;Persist Security Info=False;"
dbConn = New db.OleDb.OleDbConnection(sConnection)
dbConn.Open()
' MessageBox.Show(dbConn.State.ToString())
Dim sql, fn, ln As String
Dim dbCmd As db.OleDb.OleDbCommand
Dim dbReader As OleDb.OleDbDataReader
sql = "Select * From Customer; "
dbCmd = New db.OleDb.OleDbCommand(sql, dbConn)
dbReader = dbCmd.ExecuteReader()
Do While dbReader.Read()
fn = System.Convert.ToString(dbReader("FirstName"))
ln = System.Convert.ToString(dbReader("LastName"))
lstCustomers.Items.Add(ln + " " + fn)
Loop
End Sub
This gets FirstName and LastName from database and creates a string of it and adds it to list.
Is it possible to make an object with FirstName and LastName as property.
so that it could be accessed like c=lstCustomers.SelectedItem as Customer
c.FirstName
c.LastName
Public Sub MakeConnection()
Dim sConnection As String
Dim dbConn As db.OleDb.OleDbConnection
sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\QADEER\Documents\Customer.accdb;Persist Security Info=False;"
dbConn = New db.OleDb.OleDbConnection(sConnection)
dbConn.Open()
' MessageBox.Show(dbConn.State.ToString())
Dim sql, fn, ln As String
Dim dbCmd As db.OleDb.OleDbCommand
Dim dbReader As OleDb.OleDbDataReader
sql = "Select * From Customer; "
dbCmd = New db.OleDb.OleDbCommand(sql, dbConn)
dbReader = dbCmd.ExecuteReader()
Do While dbReader.Read()
fn = System.Convert.ToString(dbReader("FirstName"))
ln = System.Convert.ToString(dbReader("LastName"))
lstCustomers.Items.Add(ln + " " + fn)
Loop
End Sub
This gets FirstName and LastName from database and creates a string of it and adds it to list.
Is it possible to make an object with FirstName and LastName as property.
so that it could be accessed like c=lstCustomers.SelectedItem as Customer
c.FirstName
c.LastName