DataSet Tables into Access tables with Oledb?

N

Nevyn Twyll

I've got several datatables in a dataset that I've filled programattically.
The structure of the datatables match the structure of tables in an access
database.

What is an easy, programmatic way to insert all those datatable records into
the tables in Access without manually generating parameterized
InsertCommands for an OleDBDataAdapter?

I tried the following using an OleDbCommandBuilder to try and build the
InsertCOmmand,, and it generated an error "Microsoft JET Database Engine:
Operation must use an updateable query."


Dictionary.ECMDBDataset.MyDataTable dtMyTable;
OleDbConnection odbConn;

<...>

OleDbDataAdapter odbadapt = new OleDbDataAdapter();


odbadapt.SelectCommand = new OleDbCommand("SELECT Myfield1, Myfield2 From
[MyDataTable];", odbConn );

OleDbCommandBuilder cb = new OleDbCommandBuilder(odbadapt);

odbadapt.InsertCommand = cb.GetInsertCommand();

odbadapt.Update(dtTableList);


Help?
 
N

Nevyn Twyll

I can't seem to use the templates on your website - they download without a
file extension, and when i try to open them as a .cst in CodeSmith, it
generates an error.

Help?

Miha Markic said:
Hi Nevyn,

You might drag&drop table from Server Explorer to the form - it will
autogenerate an adapter for you.
Other way: you might try using my template (for free utility CodeSmith) to
autogenerate the adapter:
http://www.rthand.com/DesktopModule...alias=RightHand&lang=en-US&ItemID=7&mid=10244

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com


Nevyn Twyll said:
I've got several datatables in a dataset that I've filled
programattically.
The structure of the datatables match the structure of tables in an
access database.

What is an easy, programmatic way to insert all those datatable records
into the tables in Access without manually generating parameterized
InsertCommands for an OleDBDataAdapter?

I tried the following using an OleDbCommandBuilder to try and build the
InsertCOmmand,, and it generated an error "Microsoft JET Database Engine:
Operation must use an updateable query."


Dictionary.ECMDBDataset.MyDataTable dtMyTable;
OleDbConnection odbConn;

<...>

OleDbDataAdapter odbadapt = new OleDbDataAdapter();


odbadapt.SelectCommand = new OleDbCommand("SELECT Myfield1, Myfield2 From
[MyDataTable];", odbConn );

OleDbCommandBuilder cb = new OleDbCommandBuilder(odbadapt);

odbadapt.InsertCommand = cb.GetInsertCommand();

odbadapt.Update(dtTableList);


Help?
 
M

Miha Markic [MVP C#]

Hi,

Try running CodeSmith and open it from within CodeSmith.
It is a text file afterall :)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Nevyn Twyll said:
I can't seem to use the templates on your website - they download without a
file extension, and when i try to open them as a .cst in CodeSmith, it
generates an error.

Help?

Miha Markic said:
Hi Nevyn,

You might drag&drop table from Server Explorer to the form - it will
autogenerate an adapter for you.
Other way: you might try using my template (for free utility CodeSmith)
to autogenerate the adapter:
http://www.rthand.com/DesktopModule...alias=RightHand&lang=en-US&ItemID=7&mid=10244

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com


Nevyn Twyll said:
I've got several datatables in a dataset that I've filled
programattically.
The structure of the datatables match the structure of tables in an
access database.

What is an easy, programmatic way to insert all those datatable records
into the tables in Access without manually generating parameterized
InsertCommands for an OleDBDataAdapter?

I tried the following using an OleDbCommandBuilder to try and build the
InsertCOmmand,, and it generated an error "Microsoft JET Database
Engine: Operation must use an updateable query."


Dictionary.ECMDBDataset.MyDataTable dtMyTable;
OleDbConnection odbConn;

<...>

OleDbDataAdapter odbadapt = new OleDbDataAdapter();


odbadapt.SelectCommand = new OleDbCommand("SELECT Myfield1, Myfield2
From [MyDataTable];", odbConn );

OleDbCommandBuilder cb = new OleDbCommandBuilder(odbadapt);

odbadapt.InsertCommand = cb.GetInsertCommand();

odbadapt.Update(dtTableList);


Help?
 
N

Nevyn Twyll

Yeah, I did. It generates an error.

Miha Markic said:
Hi,

Try running CodeSmith and open it from within CodeSmith.
It is a text file afterall :)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Nevyn Twyll said:
I can't seem to use the templates on your website - they download without
a file extension, and when i try to open them as a .cst in CodeSmith, it
generates an error.

Help?

Miha Markic said:
Hi Nevyn,

You might drag&drop table from Server Explorer to the form - it will
autogenerate an adapter for you.
Other way: you might try using my template (for free utility CodeSmith)
to autogenerate the adapter:
http://www.rthand.com/DesktopModule...alias=RightHand&lang=en-US&ItemID=7&mid=10244

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com


I've got several datatables in a dataset that I've filled
programattically.
The structure of the datatables match the structure of tables in an
access database.

What is an easy, programmatic way to insert all those datatable records
into the tables in Access without manually generating parameterized
InsertCommands for an OleDBDataAdapter?

I tried the following using an OleDbCommandBuilder to try and build the
InsertCOmmand,, and it generated an error "Microsoft JET Database
Engine: Operation must use an updateable query."


Dictionary.ECMDBDataset.MyDataTable dtMyTable;
OleDbConnection odbConn;

<...>

OleDbDataAdapter odbadapt = new OleDbDataAdapter();


odbadapt.SelectCommand = new OleDbCommand("SELECT Myfield1, Myfield2
From [MyDataTable];", odbConn );

OleDbCommandBuilder cb = new OleDbCommandBuilder(odbadapt);

odbadapt.InsertCommand = cb.GetInsertCommand();

odbadapt.Update(dtTableList);


Help?
 
N

Nevyn Twyll

Yeah, I did. It generates an error.

Miha Markic said:
Hi,

Try running CodeSmith and open it from within CodeSmith.
It is a text file afterall :)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Nevyn Twyll said:
I can't seem to use the templates on your website - they download without
a file extension, and when i try to open them as a .cst in CodeSmith, it
generates an error.

Help?

Miha Markic said:
Hi Nevyn,

You might drag&drop table from Server Explorer to the form - it will
autogenerate an adapter for you.
Other way: you might try using my template (for free utility CodeSmith)
to autogenerate the adapter:
http://www.rthand.com/DesktopModule...alias=RightHand&lang=en-US&ItemID=7&mid=10244

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com


I've got several datatables in a dataset that I've filled
programattically.
The structure of the datatables match the structure of tables in an
access database.

What is an easy, programmatic way to insert all those datatable records
into the tables in Access without manually generating parameterized
InsertCommands for an OleDBDataAdapter?

I tried the following using an OleDbCommandBuilder to try and build the
InsertCOmmand,, and it generated an error "Microsoft JET Database
Engine: Operation must use an updateable query."


Dictionary.ECMDBDataset.MyDataTable dtMyTable;
OleDbConnection odbConn;

<...>

OleDbDataAdapter odbadapt = new OleDbDataAdapter();


odbadapt.SelectCommand = new OleDbCommand("SELECT Myfield1, Myfield2
From [MyDataTable];", odbConn );

OleDbCommandBuilder cb = new OleDbCommandBuilder(odbadapt);

odbadapt.InsertCommand = cb.GetInsertCommand();

odbadapt.Update(dtTableList);


Help?
 
N

Nevyn Twyll

Okay, I'm lame but I'm not that lame.
It causes a parse error on opening.

Miha Markic said:
Hi,

Try running CodeSmith and open it from within CodeSmith.
It is a text file afterall :)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Nevyn Twyll said:
I can't seem to use the templates on your website - they download without
a file extension, and when i try to open them as a .cst in CodeSmith, it
generates an error.

Help?

Miha Markic said:
Hi Nevyn,

You might drag&drop table from Server Explorer to the form - it will
autogenerate an adapter for you.
Other way: you might try using my template (for free utility CodeSmith)
to autogenerate the adapter:
http://www.rthand.com/DesktopModule...alias=RightHand&lang=en-US&ItemID=7&mid=10244

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com


I've got several datatables in a dataset that I've filled
programattically.
The structure of the datatables match the structure of tables in an
access database.

What is an easy, programmatic way to insert all those datatable records
into the tables in Access without manually generating parameterized
InsertCommands for an OleDBDataAdapter?

I tried the following using an OleDbCommandBuilder to try and build the
InsertCOmmand,, and it generated an error "Microsoft JET Database
Engine: Operation must use an updateable query."


Dictionary.ECMDBDataset.MyDataTable dtMyTable;
OleDbConnection odbConn;

<...>

OleDbDataAdapter odbadapt = new OleDbDataAdapter();


odbadapt.SelectCommand = new OleDbCommand("SELECT Myfield1, Myfield2
From [MyDataTable];", odbConn );

OleDbCommandBuilder cb = new OleDbCommandBuilder(odbadapt);

odbadapt.InsertCommand = cb.GetInsertCommand();

odbadapt.Update(dtTableList);


Help?
 

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

Top