|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How can we insert a DataTable into database?I have a typed DataSet with a DataTable in it.
The structure of the DataTable is from a table in a database. Now I have make the DataTble with about 10 new row. How can I insert the DataTable into database at once? Ehm, by using DataSet.Tables.Add method?
-- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "ad" <fly***@wfes.tcc.edu.tw> wrote in message news:ORrnOgIpGHA.4848@TK2MSFTNGP03.phx.gbl... >I have a typed DataSet with a DataTable in it. > The structure of the DataTable is from a table in a database. > > Now I have make the DataTble with about 10 new row. > How can I insert the DataTable into database at once? > Duh, I misread dataset instead of database.
Assuming you are using vs.net 2003 just drag & drop proper dataadapter from toolbox on the form - wizard will show up and guide you... -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:eL0YEbMpGHA.3324@TK2MSFTNGP05.phx.gbl... > Ehm, by using DataSet.Tables.Add method? > > -- > Miha Markic [MVP C#, INETA Country Leader for Slovenia] > RightHand .NET consulting & development www.rthand.com > Blog: http://cs.rthand.com/blogs/blog_with_righthand/ > > "ad" <fly***@wfes.tcc.edu.tw> wrote in message > news:ORrnOgIpGHA.4848@TK2MSFTNGP03.phx.gbl... >>I have a typed DataSet with a DataTable in it. >> The structure of the DataTable is from a table in a database. >> >> Now I have make the DataTble with about 10 new row. >> How can I insert the DataTable into database at once? >> > > Define an insert stored procedure as you normally would if you were
doing a single insert. Create a sql connection Then in your code define a SqlDataAdapter (or data adapter for the type of database you use). You create a sqlcommand with the insert stored procedure specified. Then set the sqldataadapters insertcommand property to the sql command you just created. Then if you call the Sql data adapters Update method and pass in the datatable. check out the following link http://msdn2.microsoft.com/en-us/library/59x02y99.aspx Please note, the insertcommand will be fired when you call the Update method. The dataadapter knows what to do for each row by checking the rows state. So if the rows rowstate is new then it would be inserted using the insert command, if it is modified it would be updated using the update command, if it is deleted it would use the delete command. Hope this helps Pete ad wrote: Show quote > I have a typed DataSet with a DataTable in it. > The structure of the DataTable is from a table in a database. > > Now I have make the DataTble with about 10 new row. > How can I insert the DataTable into database at once? |
|||||||||||||||||||||||