Very Simple Problem

  • Thread starter Thread starter Merlin
  • Start date Start date
M

Merlin

Hello All,

Hope somebody wouldn`t mind helping me, i have a problem and as a newbie I
don`t know where im going wrong:

I keep getting the following error "An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll" on the line
that says: "daPatientsIDs.Fill(dtPatientsIDs)"

When trying to run this Code:

'CODE START
Option Strict On
Imports System.Data.OleDb

Public Class Form1
Inherits System.Windows.Forms.Form

Dim dbConnection As OleDbConnection
Dim dbCommand As OleDbCommand
Dim dbDataAdapter As OleDbDataAdapter
Dim ConnectString As String = "Provider = Microsoft.Jet.OLEDB.4.0;" &
"Data Source = Hospital.MDB"
Dim dtPatientsIDs As New DataTable()
Dim daPatientsIDs As New OleDbDataAdapter("Select [Patients ID] from
Patients", ConnectString)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daPatientsIDs.Fill(dtPatientsIDs)
lstPatientIDs.DataSource = dtPatientsIDs
lstPatientIDs.DisplayMember = "Patient ID"

OleDbDataAdapter.Fill(dsPatientsAndWards)

txtWardName.DataBindings.Add("Text", dsPatientsAndWards, "Patients.Ward
Name")
txtWardType.DataBindings.Add("Text", dsPatientsAndWards, "Patients.Ward
Type")

End Sub
End Class
'CODE FINISH

Anybody shed any light on this?

Regards
Merlin
 
Merlin said:
Hello All,

Hope somebody wouldn`t mind helping me, i have a problem and as a newbie I
don`t know where im going wrong:

I keep getting the following error "An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll" on the line
that says: "daPatientsIDs.Fill(dtPatientsIDs)"


You need to put your fill statement in a try block, that way you will get a
descriptive error. Something like this:

....
Try
OleDbDataAdapter.Fill(dsPatientsAndWards)
Catch Ex as Exception
Console.WriteLine("Error: " & ex.Message)
Msgbox("Error: " & Ex.Message)
End Try
....

Then run it again, and give us the descriptive error message.

~
Jeremy
 
Merlin said:
Hope somebody wouldn`t mind helping me, i have a problem and as a
newbie I don`t know where im going wrong:

I keep getting the following error "An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll" on
the line that says: "daPatientsIDs.Fill(dtPatientsIDs)"

Already tried putting it in a try-catch block and examining the thrown
exception? Exception should contain details.

If it turns out to be an ADO.NET related question: Right group is
microsoft.public.dotnet.framework.adonet
 
Jeremy i`ve put the code in Try Expressions like you said and it throws up:

"Additional information: This would cause two bindings in the collection to
bind to the same property." on:

txtWardName.DataBindings.Add("Text", dsPatientsAndWards, "Patients.Ward
Name")
txtWardType.DataBindings.Add("Text", dsPatientsAndWards, "Patients.Ward
Type")

In my book that im working from it say "In the Forms Load event, write the
following code to fill the dataset from the the data adapter and then to
bind the two textboxes displaying details about the wards to the ward name
and ward type fields in the dataset"

Thanks for you help so far

Ta
Merlin
 
Merlin said:
Jeremy i`ve put the code in Try Expressions like you said and it throws up:

"Additional information: This would cause two bindings in the collection to
bind to the same property." on:

txtWardName.DataBindings.Add("Text", dsPatientsAndWards, "Patients.Ward
Name")
txtWardType.DataBindings.Add("Text", dsPatientsAndWards, "Patients.Ward
Type")

In my book that im working from it say "In the Forms Load event, write the
following code to fill the dataset from the the data adapter and then to
bind the two textboxes displaying details about the wards to the ward name
and ward type fields in the dataset"


My *guess* is that your code is executing more than once, and doubling the
bindings, however this question really belongs in the ADO.NET Group:

microsoft.public.dotnet.framework.adonet


~
Jeremy
 
One other thing you might try is stepping through each line of code to see
exactly when it crashes. You can do this by selecting "Debug > Step Into"
on the main menu at Design Time (while the app is NOT running) or F8 if you
use VB Classic key bindings.

~
Jeremy
 
Back
Top