B
Brad
Here is my code:
Dim i As Integer
Dim oledcstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\UKC Application Services\UKCJuniors\UKCJuniors\Juniors.mdb"
Dim thisQuery As String = "SELECT YTDPts, FirstName, LastName, City, State
FROM JuniorMaster WHERE (Region = 1) ORDER BY YTDPts"
Dim olecn As New OleDbConnection(oledcstring)
Dim oledc As New OleDbCommand(thisQuery, olecn)
Dim oledr As OleDbDataReader
Dim resultView As DataView
Dim resultTable As DataTable = New DataTable("Results")
Dim resultRow As DataRow
'Make the table to store the results
Dim Place, FirstName, LastName, City, State, YTDPts As DataColumn
Place = New DataColumn()
Place.DataType = System.Type.GetType("System.String")
Place.Caption = "Place"
Place.ColumnName = "Place"
FirstName = New DataColumn()
FirstName.DataType = System.Type.GetType("System.String")
FirstName.Caption = "FirstName"
FirstName.ColumnName = "First Name"
LastName = New DataColumn()
LastName.DataType = System.Type.GetType("System.String")
LastName.Caption = "LastName"
LastName.ColumnName = "Last Name"
City = New DataColumn()
City.DataType = System.Type.GetType("System.String")
City.Caption = "City"
City.ColumnName = "City"
State = New DataColumn()
State.DataType = System.Type.GetType("System.String")
State.Caption = "State"
State.ColumnName = "State"
YTDPts = New DataColumn()
YTDPts.DataType = System.Type.GetType("System.Decimal")
YTDPts.Caption = "YTDPts"
YTDPts.ColumnName = "YTD Points"
resultTable.Columns.Add(Place)
resultTable.Columns.Add(FirstName)
resultTable.Columns.Add(LastName)
resultTable.Columns.Add(City)
resultTable.Columns.Add(State)
resultTable.Columns.Add(YTDPts)
' run the command for Region 1
olecn.Open()
oledr = oledc.ExecuteReader()
For i = 0 To 49
oledr.Read()
resultRow = resultTable.NewRow()
resultRow("Place") = i + 1
resultRow("FirstName") = oledr("FirstName")
resultRow("LastName") = oledr("LastName")
resultRow("City") = oledr("City")
resultRow("State") = oledr("State")
resultRow("YTDPts") = oledr("YTDPts")
Next
resultView.Table = resultTable
dgResults.DataSource = resultView
oledr.Close()
olecn.Close()
On the line of oledr=oledc.ExecuteReader I get the following error: An
unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll.
I have been searching through articles and help files and cannot find
anything. If the above coding is sloppy, I apologize in advance for being a
beginner.
Thanks for any help provided.
Brad
Dim i As Integer
Dim oledcstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\UKC Application Services\UKCJuniors\UKCJuniors\Juniors.mdb"
Dim thisQuery As String = "SELECT YTDPts, FirstName, LastName, City, State
FROM JuniorMaster WHERE (Region = 1) ORDER BY YTDPts"
Dim olecn As New OleDbConnection(oledcstring)
Dim oledc As New OleDbCommand(thisQuery, olecn)
Dim oledr As OleDbDataReader
Dim resultView As DataView
Dim resultTable As DataTable = New DataTable("Results")
Dim resultRow As DataRow
'Make the table to store the results
Dim Place, FirstName, LastName, City, State, YTDPts As DataColumn
Place = New DataColumn()
Place.DataType = System.Type.GetType("System.String")
Place.Caption = "Place"
Place.ColumnName = "Place"
FirstName = New DataColumn()
FirstName.DataType = System.Type.GetType("System.String")
FirstName.Caption = "FirstName"
FirstName.ColumnName = "First Name"
LastName = New DataColumn()
LastName.DataType = System.Type.GetType("System.String")
LastName.Caption = "LastName"
LastName.ColumnName = "Last Name"
City = New DataColumn()
City.DataType = System.Type.GetType("System.String")
City.Caption = "City"
City.ColumnName = "City"
State = New DataColumn()
State.DataType = System.Type.GetType("System.String")
State.Caption = "State"
State.ColumnName = "State"
YTDPts = New DataColumn()
YTDPts.DataType = System.Type.GetType("System.Decimal")
YTDPts.Caption = "YTDPts"
YTDPts.ColumnName = "YTD Points"
resultTable.Columns.Add(Place)
resultTable.Columns.Add(FirstName)
resultTable.Columns.Add(LastName)
resultTable.Columns.Add(City)
resultTable.Columns.Add(State)
resultTable.Columns.Add(YTDPts)
' run the command for Region 1
olecn.Open()
oledr = oledc.ExecuteReader()
For i = 0 To 49
oledr.Read()
resultRow = resultTable.NewRow()
resultRow("Place") = i + 1
resultRow("FirstName") = oledr("FirstName")
resultRow("LastName") = oledr("LastName")
resultRow("City") = oledr("City")
resultRow("State") = oledr("State")
resultRow("YTDPts") = oledr("YTDPts")
Next
resultView.Table = resultTable
dgResults.DataSource = resultView
oledr.Close()
olecn.Close()
On the line of oledr=oledc.ExecuteReader I get the following error: An
unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll.
I have been searching through articles and help files and cannot find
anything. If the above coding is sloppy, I apologize in advance for being a
beginner.
Thanks for any help provided.
Brad