Solved

How can I generate a table in sql from a .txt file?

Posted on 2009-07-06
6
223 Views
Last Modified: 2012-05-07
I have a tab-delimited text file with something like 66 columns/fields from amazon.  I want to generate a table so that I don't have to explicitly define it myself much like I can do in Excel. However, I have created a program that writes an Schema.ini file that already explicity describes the file from which I make an OldDbConnection, OleDbDataAdapter, and subsequently fill into a dataSeta.  So , I believe I have a couple options?  Thanks.
0
Comment
Question by:MotoDev
  • 4
  • 2
6 Comments
 
LVL 22

Expert Comment

by:8080_Diver
ID: 24790488
First, some questions:
  1. Does the CSV file have column names?
  2. Are the Text columns enclosed in quotes?
  3. Are there any embedded commas in any of the text fields?
While it is possible to do this in a stored proc, I would be tempted to use an application to accomplish this task simply because this is the sort of thing that can be done well and easily in an application and may not be quite as easy in a stored proc.  (Remember, SQL works on sets of data rather than on individual lines/records and, therefore, one has to be able to treat the data asa set. ;-)
0
 

Author Comment

by:MotoDev
ID: 24790616
To answer your questions: Yes, the .txt file has column names in the first or header line, No, there are no quotes. (Ps I hate quotes). Yes, there are commas.

First, some questions: Does the CSV file have column names?  Are the Text columns enclosed in quotes?  Are there any embedded commas in any of the text fields?  And, I failed to mention I do have an application written in VS 2008 C#. Any thoughts...?

While it is possible to do this in a stored proc, I would be tempted to use an application to accomplish this task simply because this is the sort of thing that can be done well and easily in an application and may not be quite as easy in a stored proc.  (Remember, SQL works on sets of data rather than on individual lines/records and, therefore, one has to be able to treat the data asa set. ;-)
0
 

Author Comment

by:MotoDev
ID: 24793600
I found my answer under the title 'Get data from a Dataset into SQL Server 2000'
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 22

Expert Comment

by:8080_Diver
ID: 24800308
To answer your questions: Yes, the .txt file has column names in the first or header line, No, there are no quotes. (Ps I hate quotes). Yes, there are commas.
You may want to be careful, though.  Having a comma in the middle of a text column turns that text column into 2 text columns unless the text is wrapped in qoutes.  (You may hate quotes but they are useful for this sort of thing. ;-)
 
0
 

Author Comment

by:MotoDev
ID: 24803491
I would still like to see it done.
0
 

Accepted Solution

by:
MotoDev earned 0 total points
ID: 24803559
Just to clarify, The text file is Tab-delimited.  And I can pull the dataset(66 fields and data) into datagrid.  Is their a way to create a sql table in C#?
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question