Hi all,
I am creating a table and populating it in runtime, then I want to save it in database.
How can I do that using ADO.NET?
Thanks.
Victor
Printable View
Hi all,
I am creating a table and populating it in runtime, then I want to save it in database.
How can I do that using ADO.NET?
Thanks.
Victor
Use a dataadapter and specify an update command for it.
OR,
Loop through the datatable and build your own command and execute it against the database. (The dataadapter does this internally).
I am assuming that ado.net is pretty smart and I already have all info about the table in DataTable object. So, if I will just loop through columns to create table and loop through rows to insert data, I will be doing just kind of extra work, which is already done.
I hope that there is some way to just submit entire table (to create table and insert rows in it) by using ADO.NET functions.
Any ideas?
What Hellswraith said.
dataadapter1.Update(dataset1, "myTableName")
There is no table in database yet, it is only in memory in dataset. Nothing to update.
It maybe would have any meaning, but dataadapter doesn't have connection. To create dataadapter, you need to submit sql query and connection string.
I guess I'm not sure what you mean. You want to create a table and populate it in code, then add it to a database?
Correct
I think this question deserves answering.
(because I'm doing the same thing!)
What I"m finding is that INSERT and UPDATE SQL commands are becoming my new best friend.