problem with OleDbDataAdapter

  • Thread starter Thread starter shachar
  • Start date Start date
S

shachar

hi all.
i wrote this code and i get an error msg:
Private Pr_MyCon As new System.Data.OleDb.OleDbConnection
Private Pr_DataSet As new DataSet("Temp")
Private Pr_DataAdapter As
system.Data.OleDb.OleDbDataAdapter

Pr_MyCon.ConnectionString ="....."
Pr_DataAdapter = New OleDb.OleDbDataAdapter("select *
from MyTable", Pr_MyCon)
Pr_MyCon.open()
Pr_DataAdapter.Fill(Pr_DataSet, "MyTable")
the eror msg syas:"An unhandled exception of
type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll"
why?
 
The most likely cause is that you are explicitly opening the databse and tha
DataAdapter is spitting it's dummy because the connection is already open
when it attempts to execute the Fill method.

The DataAdapter will open and close the connection as required.

Remove your explicit open and all should be well.
 
Shachar,

In addition to Stephany,

A connection needs for every open an close (or with the connection better
instead of that a dispose and when you do that, you have to add the
connectionstring again).

Told is that the best practise of that is:
With anything else than a dataadapter just to do that open and dispose
consequently.
With a dataadapter with one fill let it be done by the dataadapter
With a dataadapter with a lot of sequential fills do an open and dispose
consequently

However never leave you connection open when it is not doing something.

(With the exception for an access database to prevent deleting that in the
meantime, however than you have to set the connection in the load event and
the close in the closing event)

I hope this helps?

Cor
 
i took off the connection implicit opening - BUT it still
gives the same error msg!!
why?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top