foster30
asked on
Unhandled exception of type..
Hi Experts,
Iv'e been following an ADO tutorial in a SAMS teach yourself VB.NET book. The code matches mine, however I am trying to apply it to my database rather than the example db.
I am getting this error:
An unhandled exception of type 'System.Data.OleDb.OleDbEx ception' occurred in system.data.dll
from this peice of code:
m_daDataAdapter.Fill(m_dtC ustomers)
This is the code that I have so far...
Public Class txt
'declare modules
Inherits System.Windows.Forms.Form
Private m_cnADONetConnection As New OleDb.OleDbConnection
Private m_daDataAdapter As New OleDb.OleDbDataAdapter
Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
Private m_dtCustomers As New DataTable
Private m_rowPosition As Integer = 0
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents txtContactName As System.Windows.Forms.TextB ox
Friend WithEvents txtAddress1 As System.Windows.Forms.TextB ox
Friend WithEvents txtAddress2 As System.Windows.Forms.TextB ox
Friend WithEvents txtPostcode As System.Windows.Forms.TextB ox
Friend WithEvents txtPhoneNo As System.Windows.Forms.TextB ox
Friend WithEvents txtID As System.Windows.Forms.TextB ox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.txtContactName = New System.Windows.Forms.TextB ox
Me.txtAddress1 = New System.Windows.Forms.TextB ox
Me.txtAddress2 = New System.Windows.Forms.TextB ox
Me.txtPostcode = New System.Windows.Forms.TextB ox
Me.txtPhoneNo = New System.Windows.Forms.TextB ox
Me.txtID = New System.Windows.Forms.TextB ox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'txtContactName
'
Me.txtContactName.Location = New System.Drawing.Point(88, 32)
Me.txtContactName.Name = "txtContactName"
Me.txtContactName.Size = New System.Drawing.Size(152, 20)
Me.txtContactName.TabIndex = 0
Me.txtContactName.Text = ""
'
'txtAddress1
'
Me.txtAddress1.Location = New System.Drawing.Point(88, 64)
Me.txtAddress1.Name = "txtAddress1"
Me.txtAddress1.Size = New System.Drawing.Size(152, 20)
Me.txtAddress1.TabIndex = 1
Me.txtAddress1.Text = ""
'
'txtAddress2
'
Me.txtAddress2.Location = New System.Drawing.Point(88, 96)
Me.txtAddress2.Name = "txtAddress2"
Me.txtAddress2.Size = New System.Drawing.Size(152, 20)
Me.txtAddress2.TabIndex = 2
Me.txtAddress2.Text = ""
'
'txtPostcode
'
Me.txtPostcode.Location = New System.Drawing.Point(88, 128)
Me.txtPostcode.Name = "txtPostcode"
Me.txtPostcode.Size = New System.Drawing.Size(152, 20)
Me.txtPostcode.TabIndex = 3
Me.txtPostcode.Text = ""
'
'txtPhoneNo
'
Me.txtPhoneNo.Location = New System.Drawing.Point(88, 160)
Me.txtPhoneNo.Name = "txtPhoneNo"
Me.txtPhoneNo.Size = New System.Drawing.Size(152, 20)
Me.txtPhoneNo.TabIndex = 4
Me.txtPhoneNo.Text = ""
'
'txtID
'
Me.txtID.Location = New System.Drawing.Point(88, 192)
Me.txtID.Name = "txtID"
Me.txtID.Size = New System.Drawing.Size(152, 20)
Me.txtID.TabIndex = 5
Me.txtID.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 32)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(40, 32)
Me.Label1.TabIndex = 6
Me.Label1.Text = "Name"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(24, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 32)
Me.Label2.TabIndex = 7
Me.Label2.Text = "Address1"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(24, 96)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 32)
Me.Label3.TabIndex = 8
Me.Label3.Text = "Address2"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(24, 128)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(64, 32)
Me.Label4.TabIndex = 9
Me.Label4.Text = "Postcode"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(24, 160)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(64, 32)
Me.Label5.TabIndex = 10
Me.Label5.Text = "Phone No"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(24, 192)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(40, 32)
Me.Label6.TabIndex = 11
Me.Label6.Text = "ID"
'
'txt
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(376, 366)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtID)
Me.Controls.Add(Me.txtPhon eNo)
Me.Controls.Add(Me.txtPost code)
Me.Controls.Add(Me.txtAddr ess2)
Me.Controls.Add(Me.txtAddr ess1)
Me.Controls.Add(Me.txtCont actName)
Me.Name = "txt"
Me.Text = "Cust"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Cust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'run connection string
m_cnADONetConnection.Conne ctionStrin g = _
"Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=C:\Documents and Settings\Dave\My Documents\DVDHire.mdb"
'open connection
m_cnADONetConnection.Open( )
'dataadapter
m_daDataAdapter = _
New OleDb.OleDbDataAdapter("Se lect * From Contacts", m_cnADONetConnection)
'commandbuilder to handle updates adding and deleting
m_cbCommandBuilder = New OleDb.OleDbCommandBuilder( m_daDataAd apter)
'fill the dataset
m_daDataAdapter.Fill(m_dtC ustomers)
Me.ShowCurrentRecord()
End Sub
Private Sub Cust_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
'Close the connection
m_cnADONetConnection.Close ()
End Sub
Private Sub ShowCurrentRecord()
If m_dtCustomers.Rows.Count = 0 Then
txtContactName.Text = ""
txtAddress1.Text = ""
txtAddress2.Text = ""
txtPostcode.Text = ""
txtPhoneNo.Text = ""
txtID.Text = ""
Exit Sub
End If
txtContactName.Text = _
m_dtCustomers.Rows(m_rowPo sition)("N ame").ToSt ring()
txtAddress1.Text = _
m_dtCustomers.Rows(m_rowPo sition)("A ddress1"). ToString()
txtAddress2.Text = _
m_dtCustomers.Rows(m_rowPo sition)("A ddress2"). ToString()
txtPostcode.Text = _
m_dtCustomers.Rows(m_rowPo sition)("P ostcode"). ToString()
txtPhoneNo.Text = _
m_dtCustomers.Rows(m_rowPo sition)("T elephone No").ToString()
txtID.Text = _
m_dtCustomers.Rows(m_rowPo sition)("I D").ToStri ng()
End Sub
End Class
Can you see where I have gone wrong in trying to convert it to my database?
Iv'e been following an ADO tutorial in a SAMS teach yourself VB.NET book. The code matches mine, however I am trying to apply it to my database rather than the example db.
I am getting this error:
An unhandled exception of type 'System.Data.OleDb.OleDbEx
from this peice of code:
m_daDataAdapter.Fill(m_dtC
This is the code that I have so far...
Public Class txt
'declare modules
Inherits System.Windows.Forms.Form
Private m_cnADONetConnection As New OleDb.OleDbConnection
Private m_daDataAdapter As New OleDb.OleDbDataAdapter
Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
Private m_dtCustomers As New DataTable
Private m_rowPosition As Integer = 0
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents txtContactName As System.Windows.Forms.TextB
Friend WithEvents txtAddress1 As System.Windows.Forms.TextB
Friend WithEvents txtAddress2 As System.Windows.Forms.TextB
Friend WithEvents txtPostcode As System.Windows.Forms.TextB
Friend WithEvents txtPhoneNo As System.Windows.Forms.TextB
Friend WithEvents txtID As System.Windows.Forms.TextB
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
<System.Diagnostics.Debugg
Me.txtContactName = New System.Windows.Forms.TextB
Me.txtAddress1 = New System.Windows.Forms.TextB
Me.txtAddress2 = New System.Windows.Forms.TextB
Me.txtPostcode = New System.Windows.Forms.TextB
Me.txtPhoneNo = New System.Windows.Forms.TextB
Me.txtID = New System.Windows.Forms.TextB
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'txtContactName
'
Me.txtContactName.Location
Me.txtContactName.Name = "txtContactName"
Me.txtContactName.Size = New System.Drawing.Size(152, 20)
Me.txtContactName.TabIndex
Me.txtContactName.Text = ""
'
'txtAddress1
'
Me.txtAddress1.Location = New System.Drawing.Point(88, 64)
Me.txtAddress1.Name = "txtAddress1"
Me.txtAddress1.Size = New System.Drawing.Size(152, 20)
Me.txtAddress1.TabIndex = 1
Me.txtAddress1.Text = ""
'
'txtAddress2
'
Me.txtAddress2.Location = New System.Drawing.Point(88, 96)
Me.txtAddress2.Name = "txtAddress2"
Me.txtAddress2.Size = New System.Drawing.Size(152, 20)
Me.txtAddress2.TabIndex = 2
Me.txtAddress2.Text = ""
'
'txtPostcode
'
Me.txtPostcode.Location = New System.Drawing.Point(88, 128)
Me.txtPostcode.Name = "txtPostcode"
Me.txtPostcode.Size = New System.Drawing.Size(152, 20)
Me.txtPostcode.TabIndex = 3
Me.txtPostcode.Text = ""
'
'txtPhoneNo
'
Me.txtPhoneNo.Location = New System.Drawing.Point(88, 160)
Me.txtPhoneNo.Name = "txtPhoneNo"
Me.txtPhoneNo.Size = New System.Drawing.Size(152, 20)
Me.txtPhoneNo.TabIndex = 4
Me.txtPhoneNo.Text = ""
'
'txtID
'
Me.txtID.Location = New System.Drawing.Point(88, 192)
Me.txtID.Name = "txtID"
Me.txtID.Size = New System.Drawing.Size(152, 20)
Me.txtID.TabIndex = 5
Me.txtID.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 32)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(40, 32)
Me.Label1.TabIndex = 6
Me.Label1.Text = "Name"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(24, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 32)
Me.Label2.TabIndex = 7
Me.Label2.Text = "Address1"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(24, 96)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 32)
Me.Label3.TabIndex = 8
Me.Label3.Text = "Address2"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(24, 128)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(64, 32)
Me.Label4.TabIndex = 9
Me.Label4.Text = "Postcode"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(24, 160)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(64, 32)
Me.Label5.TabIndex = 10
Me.Label5.Text = "Phone No"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(24, 192)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(40, 32)
Me.Label6.TabIndex = 11
Me.Label6.Text = "ID"
'
'txt
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(376, 366)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtID)
Me.Controls.Add(Me.txtPhon
Me.Controls.Add(Me.txtPost
Me.Controls.Add(Me.txtAddr
Me.Controls.Add(Me.txtAddr
Me.Controls.Add(Me.txtCont
Me.Name = "txt"
Me.Text = "Cust"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Cust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'run connection string
m_cnADONetConnection.Conne
"Provider=Microsoft.Jet.OL
'open connection
m_cnADONetConnection.Open(
'dataadapter
m_daDataAdapter = _
New OleDb.OleDbDataAdapter("Se
'commandbuilder to handle updates adding and deleting
m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(
'fill the dataset
m_daDataAdapter.Fill(m_dtC
Me.ShowCurrentRecord()
End Sub
Private Sub Cust_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
'Close the connection
m_cnADONetConnection.Close
End Sub
Private Sub ShowCurrentRecord()
If m_dtCustomers.Rows.Count = 0 Then
txtContactName.Text = ""
txtAddress1.Text = ""
txtAddress2.Text = ""
txtPostcode.Text = ""
txtPhoneNo.Text = ""
txtID.Text = ""
Exit Sub
End If
txtContactName.Text = _
m_dtCustomers.Rows(m_rowPo
txtAddress1.Text = _
m_dtCustomers.Rows(m_rowPo
txtAddress2.Text = _
m_dtCustomers.Rows(m_rowPo
txtPostcode.Text = _
m_dtCustomers.Rows(m_rowPo
txtPhoneNo.Text = _
m_dtCustomers.Rows(m_rowPo
txtID.Text = _
m_dtCustomers.Rows(m_rowPo
End Sub
End Class
Can you see where I have gone wrong in trying to convert it to my database?
I just pasted your code in one of my apps pointing to one of my databases and it work fine. Does the exception give you any more information?
ASKER
The following line of code is highlighted in green...
m_daDataAdapter.Fill(m_dtS tock)
the following error appears in a msg box entitled Microsoft Development Environment
An unhandled exception of type 'System.Data.OleDb.OleDbEx ception' occurred in system.data.dll
I am given the option to continue or break, when I continue, the debug box at the bottom appears with the following..
at DVD.Stock.Main() in C:\Documents and Settings\Dave\My Documents\DVD\Stock.vb:lin e 1The program '[2916] DVD.exe' has exited with code 0 (0x0).
I'll try building this on a different PC today, if that doesn't work I'll try changing the database (which I can access manually fine)
I've just realised that the database and the program have the same name, could that be an issue?
m_daDataAdapter.Fill(m_dtS
the following error appears in a msg box entitled Microsoft Development Environment
An unhandled exception of type 'System.Data.OleDb.OleDbEx
I am given the option to continue or break, when I continue, the debug box at the bottom appears with the following..
at DVD.Stock.Main() in C:\Documents and Settings\Dave\My Documents\DVD\Stock.vb:lin
I'll try building this on a different PC today, if that doesn't work I'll try changing the database (which I can access manually fine)
I've just realised that the database and the program have the same name, could that be an issue?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
okay thanks, I will comment back soon.
ASKER
manch was right, my sql command was wrong, had got my tables mixed up on my forms.
thanks a lot guys.
thanks a lot guys.