Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Importing Data into SQL Server DB

Author  Topic 

oufan222
Starting Member

6 Posts

Posted - 2010-03-27 : 21:24:43
I'm new to SQL programming, but I've been reading for several months now. However, I can't seem to find a solution to a problem I am having.

I have a tab delimited file of project data that I need to import into a SQL Server DB. I can read the file into a datatable in C# and use a dataadapter to import the the complete data set into the DB, no problem.

However, for my database design to be more efficient, it is required that I split the input file into multiple tables and use foreign keys to point to repeated fields. What is the best way to split my datatable into multiple tables? I've been reading about LINQ, because I think it allows me to query a datatable to only pull out the fields I need. However I'm not sure what to do with the query results once I obtain them. Do I insert them into a datatable (so I can use a dataadapter to insert them into my DB)? If so, how is this done? Is this the best way to accomplish what I am trying to do?

Thanks in advance for any help.

Sachin.Nand

2937 Posts

Posted - 2010-03-28 : 04:03:43
Have look here

http://www.dotnet4all.com/Dot-Net-Books/2005/02/how-to-use-insert-into-with.html

PBUH
Go to Top of Page

oufan222
Starting Member

6 Posts

Posted - 2010-03-29 : 21:44:39
That doesn't really answer my question... I know how to insert data into the database using a dataadapter. The problem is with splitting the data from a datatable.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-29 : 22:21:59
Do you have to use C# to import the data? SQL Server can natively handle a tab delimited file via BULK INSERT command, bcp.exe, or DTS/SSIS.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

oufan222
Starting Member

6 Posts

Posted - 2010-03-30 : 08:30:09
Can SQL only pull from certain columns in the tab delimited file? The problem is I have a very large file that I need to split into multiple tables.

BTW, I think I'm almost there. If I could get the sqldataadapter to work I would be finished (I think). When I use the sqldataadapter to fill a datatable, the primary key information does not get addeded to my datatable. When I use MissingSchemaAction.AddWithKey, primary key information is added to my datatable, but the autoincrement properties are somehow missing. I'm a little timid to set those in my c# app myself. It seems like those should be inherited via the MissingSchemaAction.AddWithKey call.
Go to Top of Page
   

- Advertisement -