How to persists a DataSet in a Access Table

M

Maury

Hi,
I would like to persist a Dataset Table
in an Access Table

I have a Access Database and I saved
the data in a XML file:

string strSQL = "SELECT * FROM "+TableName;
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(strSQL, myConnection);
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet, TableName);
myConnection.Close();
myDataSet.WriteXml(@"C:\Inetpub\wwwroot\xxx\Write\"+TableName+".xml");


Then I delete all rows from the Access table and I read the Xml:

DataSet myDataSet = new DataSet();
myDataSet.ReadXml(@"C:\Inetpub\wwwroot\xxx\Write\"+TableName+".xml");

but now I would like to save back the data (in myDataSet) into the table.

By now I do this "row by row" but I don't like this
Is there some better solution?

Thanks

M.A.
 
B

bhawin13

Hello Maury,
Check wheather insert , delete and update commands are generated
automatacally by DataAdapter or not. If not then create. and update the
dataset after loading xml file.
For detail please refer DataAdapter's documentation.

Regards,
bhawin13
 
M

Maury

(e-mail address removed) ha scritto:
Check wheather insert , delete and update commands are generated
automatacally by DataAdapter or not. If not then create. and update the
dataset after loading xml file.

Ok, I did it, I added

OleDbCommandBuilder myCb = new OleDbCommandBuilder(myDataAdapter);

and a so this line now works fine!

myDataAdapter.Update(xmlDataSet.Tables[TableName]);

But I would like to create a new table from
xml schema? It's possible?

Thanks

M.A.
 
B

bhawin13

Hello Maury,
It means first you want to create datatable and based on your dataset
you want to create table in database.
Am I right?
If yes, I don't think so it is possible. but you can check it with
database that such table in database yes or no. If yes then just insert
new records to table if no then create table then do operation.

For that i suggest write code to create table in database in event that
will be called before the acutal data is saved to database. Check out
events of dataset, datatable and dataAdapter.

Regards,
bhawin13
 

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

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top