Solved

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

Posted on 2009-07-06
6
220 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
Comment Utility
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
Comment Utility
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
Comment Utility
I found my answer under the title 'Get data from a Dataset into SQL Server 2000'
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:8080_Diver
Comment Utility
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
Comment Utility
I would still like to see it done.
0
 

Accepted Solution

by:
MotoDev earned 0 total points
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now