I
Ivan Weiss
Hey all, I have the following code to populate a ListView control from
my Access database. The listview is displaying a list of saved projects
that the user will be able to open, edit, or delete to work on. I know
that the DataReader is more efficient and faster than a dataset, but I
was not able to figure out how to implement it. Here is the code I have
now which works:
Private Sub frmProjects_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim dbConnection As New OleDbConnection(dbConnString)
Dim myDataSet As New DataSet()
Dim myDataAdapter As OleDbDataAdapter
Dim strSql As String
Dim myDataRow As DataRow
Me.Cursor = Cursors.WaitCursor
strSql = "SELECT Projects.Project_ID, Customers.Company,
Customers.Feeder, Customers.Address1, Customers.City, Customers.State,
Projects.Status FROM Projects INNER JOIN Customers ON
Projects.Company_ID = Customers.Customer_ID ORDER BY Project_ID"
Try
dbConnection.Open()
myDataAdapter = New OleDbDataAdapter(strSql, dbConnection)
myDataAdapter.Fill(myDataSet, "DataRead")
dbConnection.Close()
For Each myDataRow In myDataSet.Tables("DataRead").Rows
Dim strDataRow As String() = {myDataRow(0),
myDataRow(1), myDataRow(2), myDataRow(3), myDataRow(4), myDataRow(5),
myDataRow(6)}
ListView.Items.Add(New ListViewItem(strDataRow))
Next
Catch
DisplayErrorMessage("frmProjects:frmProjects_Load")
End Try
myDataSet = Nothing
myDataAdapter = Nothing
Me.Cursor = Cursors.Default
End Sub
If anyone has any ideas that would be greatly appreciated
-Ivan
my Access database. The listview is displaying a list of saved projects
that the user will be able to open, edit, or delete to work on. I know
that the DataReader is more efficient and faster than a dataset, but I
was not able to figure out how to implement it. Here is the code I have
now which works:
Private Sub frmProjects_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim dbConnection As New OleDbConnection(dbConnString)
Dim myDataSet As New DataSet()
Dim myDataAdapter As OleDbDataAdapter
Dim strSql As String
Dim myDataRow As DataRow
Me.Cursor = Cursors.WaitCursor
strSql = "SELECT Projects.Project_ID, Customers.Company,
Customers.Feeder, Customers.Address1, Customers.City, Customers.State,
Projects.Status FROM Projects INNER JOIN Customers ON
Projects.Company_ID = Customers.Customer_ID ORDER BY Project_ID"
Try
dbConnection.Open()
myDataAdapter = New OleDbDataAdapter(strSql, dbConnection)
myDataAdapter.Fill(myDataSet, "DataRead")
dbConnection.Close()
For Each myDataRow In myDataSet.Tables("DataRead").Rows
Dim strDataRow As String() = {myDataRow(0),
myDataRow(1), myDataRow(2), myDataRow(3), myDataRow(4), myDataRow(5),
myDataRow(6)}
ListView.Items.Add(New ListViewItem(strDataRow))
Next
Catch
DisplayErrorMessage("frmProjects:frmProjects_Load")
End Try
myDataSet = Nothing
myDataAdapter = Nothing
Me.Cursor = Cursors.Default
End Sub
If anyone has any ideas that would be greatly appreciated
-Ivan