Chapter17 Populating The DataGrid
I am trying to populate a DataGrid using an Access 2000 database.
The example in Chapter 17 was for SQL Server so I modified the code and when I run the project, the grid is visible but not populated. Here's the code that I am using:
Imports System.Data
Imports System.Data.OleDb
PublicClass Form1
Dim objConnection AsNew OleDbConnection _
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Program Files\My Library\My Library.mdb")
Dim objDataAdapter AsNew OleDbDataAdapter
Dim objDataSet AsNew DataSet
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
objDataAdapter.SelectCommand = New OleDbCommand
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = _
"SELECT [Title], [Author]" & _
"FROM(tMyLibrary)ORDER BY [Title];"
objDataAdapter.SelectCommand.CommandType = CommandType.Text
objConnection.Open()
objDataAdapter.Fill(objDataSet, "tMyLibrary")
objConnection.Close()
grdAuthorTitles.AutoGenerateColumns = True
grdAuthorTitles.DataSource = objDataSet
grdAuthorTitles.DataMember = "tMyLibrary"
objDataAdapter = Nothing
objConnection = Nothing
EndSub
Can anyone give me any suggestions as to where I went wrong?
Milt
|