Regarding Fill method

  • Thread starter Thread starter Lora Connors
  • Start date Start date
L

Lora Connors

I have written the following code to insert records into
Access database. If I use the DataAdapter.Fill method in
the Add Command button as shown below I get the
message "Unhandled OleDbException occurred in
System.Data.dll". Ditto if I use the Fill method in the
Event procedure MyBase.load.

'GENERAL DECLARATIONS

Dim daAddMovie As New OleDbDataAdapter _
("select MovieId,MovieTitle,Cast,No_of_Copies,Rating
from movies", strConnection)
Dim tblAddMovie As New DataTable("Movies")

'SUB TO ADD RECORD TO DATATABLE

PUBLIC SUB ADD(ByVal sender As Object, ByVal e As
System.EventArgs) handles cmdAdd.Click

daAddMovie.Fill(tblAddMovie) 'Fill the Datatable
Dim Insertvalues As Object() = {Autonumber,
txtMovieTitle.Text, txtCast.Text, CInt(cmbCopies.Text),
bolRating}
tblAddMovie.LoadDataRow(Insertvalues, False)
 
Hi Lora,

Does it exception say anything more?
Could be that select statement is wrong?
Or the connection string?
 
The Exception Message Is "An Unhandled Exception of Type
System.Data.Oledb.OleDbException Occured in The Insert.Exe"
 
Hi Lora,

Let's break this down. What is the insert.exe? (is the name of the
solution 'insert'? It may be a reserved word; change the name, for one
thing)

Also, do a try catch block around the fill method - I think the error may be
not in the .fill but rather in the insert. Let's at least determine that.

Bernie
 
Let's break this down. What is the insert.exe? (is the name of the
solution 'insert'? It may be a reserved word; change the name, for one
thing)

I don't think that this is the problem - it is probably just assembly's name
:)
Also, do a try catch block around the fill method - I think the error may be
not in the .fill but rather in the insert. Let's at least determine that.

My feeling, too.
 
Lora said:
Dim Insertvalues As Object() = {Autonumber,
txtMovieTitle.Text, txtCast.Text, CInt(cmbCopies.Text),
bolRating}

Assuming the purpose of the AutoNumber variable is self-explanatory, it
must be Nothing or your insert will fail.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
Back
Top