Urgent question ?!?

keon

New member
Joined
Feb 10, 2006
Messages
4
Programming Experience
Beginner
Hi,
I need to write a code and this must be working in the afternoon :s
I need to update/insert a database with a dataset i thought using this code:
Dim S_conn As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.mdb"
Dim S_sql As String = "SELECT * FROM rij"
Dim conn As OleDbConnection
Dim dat As OleDbDataAdapter

conn = New OleDbConnection(S_conn)
dat = New OleDbDataAdapter(S_sql, conn)
dat.Update(myDataset, "rij")
but on the last line there is a problem: Update unable to find TableMapping['rij'] or DataTable 'rij'.
Can someone help me please??
greetings
Keon
 
The thing is that you have specified a SELECT query and then you are trying to execute an Update Command of the oledbdataadapter. This command is reserved for sending changes back to the database. For a SELECT command you need to call the fill method of the OleDbDataAdapter....

VB.NET:
dat.fill(mydataset,"rij")
 
vis781 said:
The thing is that you have specified a SELECT query and then you are trying to execute an Update Command of the oledbdataadapter. This command is reserved for sending changes back to the database. For a SELECT command you need to call the fill method of the OleDbDataAdapter....

VB.NET:
dat.fill(mydataset,"rij")

And how can i do an update and or an insert? If it won't work on this way?
 
The oledbdataadapter has the following methods...(amongst others)

SelectCommand - Used With the fill method and a SELECT Command i.e "SELECT * FROM table"

All the others below are action queries. They perform changes in the datasource. They all are effected from the oledbdataadapters 'update' method. But you have to tell the oledbdataadapter what you want it to do for example.....

InsertCommand
DeleteCommand
UpdateCommand
Update

VB.NET:
Dim Insert As new oledbcommand("INSERT INTO table1 VALUES 'My Name'", connection)
Oledbdataadpater.insertcommand = insert
oledbdataadapter.update(tablename)
 
And it's impossible to use directly the dataSet?

Sorry for the many questions but I have no time to find al my problems myself.

greetings
Keon
 
vis781 said:
i don't undertstand what you mean by 'Use the dataset'?

The data I want to import or update into the database is include in a dataset. I can do 2 things I can use the dataset to import or I can splits the dataSet into different parts.

If it's impossible to use the DataSet directly then i use the second methode. But then I need to know if its possible to run a loop until the end of the dataset?
 
Sorry if i'm wrong but it does'nt sound like you understand the concept of ADO.Net. I'll try to explain...

You have a dataset. inside which is a datatable (or collection of datatables). The datatable is what stores the information form you database. Inside the datatable is a colection of datarow objects. Each of these has a RowState Property. When you add new rows or change exisitng rows in your datatable the RowState of the datarow changes. DataRowState.Added for inserted rows, DataRowState.Modified for altered rows, DataRowSate.Deleted for deleted rows. When you come to update yuor database the oledbdataadapter uses this RowState to determine what OledbCommand to use... i.e

INSERT INTO
UPDATE
DELETE FROM

So when you 'use' your dataset in the update method of the dataadapter it then checks the rowstate and actions the specified commands. So you need to specify the commands that you are going to use then call the update method of the datatadapter and pass it your dataset.

With me?
 
Last edited:
Back
Top