DataSet Tables into Access tables with Oledb?

  • Thread starter Thread starter Nevyn Twyll
  • Start date Start date
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?
 
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?
 
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?
 
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?
 
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?
 
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?
 
Back
Top