473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Insert from DataTable

Is there a quick and effcient way to insert records into SQL Server database
from a DataTable (DataTable dt;) when the DataTable and the SQL Server
database contain the same field names and attributes.

I'm using VS2005 Beta 2.

Thanks.
Nov 17 '05 #1
5 13155
Necqui,

The best way to do this would be to configure a SqlDataAdapter with the
appropriate InsertCommand (because you are adding records), and then pass
the DataTable to the Update method.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Necqui Teja" <Ne*****@nospam.nospam> wrote in message
news:e%****************@TK2MSFTNGP15.phx.gbl...
Is there a quick and effcient way to insert records into SQL Server
database from a DataTable (DataTable dt;) when the DataTable and the SQL
Server database contain the same field names and attributes.

I'm using VS2005 Beta 2.

Thanks.

Nov 17 '05 #2
Hi,

Where you get the data from?

You can check the DataRow.RowState to see the status of the row, then you
could run the required query (Update, Insert ) or as Paldino said use the
SqlDataAdapter.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Necqui Teja" <Ne*****@nospam.nospam> wrote in message
news:e%****************@TK2MSFTNGP15.phx.gbl...
Is there a quick and effcient way to insert records into SQL Server
database from a DataTable (DataTable dt;) when the DataTable and the SQL
Server database contain the same field names and attributes.

I'm using VS2005 Beta 2.

Thanks.

Nov 17 '05 #3
Hi,

Where you get the data from?

You can check the DataRow.RowState to see the status of the row, then you
could run the required query (Update, Insert ) or as Paldino said use the
SqlDataAdapter.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Necqui Teja" <Ne*****@nospam.nospam> wrote in message
news:e%****************@TK2MSFTNGP15.phx.gbl...
Is there a quick and effcient way to insert records into SQL Server
database from a DataTable (DataTable dt;) when the DataTable and the SQL
Server database contain the same field names and attributes.

I'm using VS2005 Beta 2.

Thanks.

Nov 17 '05 #4
Thanks for your help.

I ended up using sqlbulkcopy provided under ado.net 2.0.

"Necqui Teja" <Ne*****@nospam.nospam> wrote in message
news:e%****************@TK2MSFTNGP15.phx.gbl...
Is there a quick and effcient way to insert records into SQL Server
database from a DataTable (DataTable dt;) when the DataTable and the SQL
Server database contain the same field names and attributes.

I'm using VS2005 Beta 2.

Thanks.

Nov 17 '05 #5
Thanks for your help.

I ended up using sqlbulkcopy provided under ado.net 2.0.

"Necqui Teja" <Ne*****@nospam.nospam> wrote in message
news:e%****************@TK2MSFTNGP15.phx.gbl...
Is there a quick and effcient way to insert records into SQL Server
database from a DataTable (DataTable dt;) when the DataTable and the SQL
Server database contain the same field names and attributes.

I'm using VS2005 Beta 2.

Thanks.

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: adi | last post by:
Hi all, Hope there is a quick fix for this: I am inserting data from one table to another on the same DB. The insert is pretty simple as in: insert into datatable(field1, field2, field3)...
0
by: a | last post by:
I've read and split a delimited text file into a dataset. It looks fine in a datagrid (5 columns and 5,000 rows), but I've been trying, without success, to then insert the resulting dataset called...
1
by: Dazz | last post by:
Hello I have made a small app to query a database which works fine. I am now adding a logging function which writes back to the database in a separate table. When I update the OleDataAdapter,...
3
by: Ed | last post by:
Hi, I want to load data to a table in Sql Server from a dataset table in my vb.net app using a dataAdapter. I know how to do this as follows (my question is to see if I can reduce the amount...
6
by: Marcel Hug | last post by:
Hi all ! I have a table in my database, which has 3 attributes. IDFailureControl, ControlDate and ControlVersion. In the following function I test, if the date of today allready exists. Then I...
5
by: gregarican | last post by:
I have a simple VC# form that validates its text boxes' contents and I want to insert these text box contents into an SQL Server 2005 Express DB. I have added the DB as a data source but right off...
2
by: krajah | last post by:
Need Help Here....... I'm using visual C#: How to insert the value that user have entered combobox and click button.The value will sent into database.This is in form1. In form2,if click button...
1
by: creamy | last post by:
Hi Guys, There is the access DB, and the SQL server. I'm building an application that can insert a new person, and details, into a DB. (simple stuff?!) i'm however using a typed dataset created in...
7
by: anu b | last post by:
Hi I need to use Clr trigger for insert command My code is as below I am using SQL server 2005 and VS 2008.... but after running this code i didnt get the result as i expexted it shows the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.