J
Joyce
Hi folks,
I am trying to run a simple program to test my data connection. The
database opens successfully but throws an exception at the
"objDataAdapter.Fill(objDataTabel)" line below. Am I doing something
thats obviously wrong here?
Thanks,
--Joyce
'---------------------------
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb
Public Class Form1
Dim strConnection As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Documents and Settings\Trilogy\" & _
"My Documents\Visual Studio 2005\Projects\dbBackStock.mdb"
Dim objConnection As New OleDbConnection(strConnection)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles MyBase.Load
objConnection.Open()
If objConnection.State = ConnectionState.Open Then
Label1.Text = "Database is Open"
Else
Label1.Text = "Database is Closed"
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles Button1.Click
Dim strSQL As String = "SELECT Description, Size FROM
tblProducts"
Dim objCommand As New OleDbCommand(strSQL, objConnection)
Dim objDataAdapter As New OleDbDataAdapter(objCommand)
Dim objDataTabel As New Data.DataTable("Products")
Dim objDataRow As DataRow
objDataAdapter.Fill(objDataTabel) '<----- Exception here
For Each objDataRow In objDataTabel.Rows
ListBox1.Items.Add(objDataRow.Item("Description") & " " &
_
objDataRow.Item("Size"))
Next
End Sub
End Class
I am trying to run a simple program to test my data connection. The
database opens successfully but throws an exception at the
"objDataAdapter.Fill(objDataTabel)" line below. Am I doing something
thats obviously wrong here?
Thanks,
--Joyce
'---------------------------
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb
Public Class Form1
Dim strConnection As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Documents and Settings\Trilogy\" & _
"My Documents\Visual Studio 2005\Projects\dbBackStock.mdb"
Dim objConnection As New OleDbConnection(strConnection)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles MyBase.Load
objConnection.Open()
If objConnection.State = ConnectionState.Open Then
Label1.Text = "Database is Open"
Else
Label1.Text = "Database is Closed"
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles Button1.Click
Dim strSQL As String = "SELECT Description, Size FROM
tblProducts"
Dim objCommand As New OleDbCommand(strSQL, objConnection)
Dim objDataAdapter As New OleDbDataAdapter(objCommand)
Dim objDataTabel As New Data.DataTable("Products")
Dim objDataRow As DataRow
objDataAdapter.Fill(objDataTabel) '<----- Exception here
For Each objDataRow In objDataTabel.Rows
ListBox1.Items.Add(objDataRow.Item("Description") & " " &
_
objDataRow.Item("Size"))
Next
End Sub
End Class