Connecting Tech Pros Worldwide Forums | Help | Site Map

Add a list stored in a text file to a SQL Server 2005 database

Member
 
Join Date: Mar 2008
Posts: 56
#1: Apr 21 '08
Hi I am coding an ASP .Net project in C# and am using connection strings to connect to a Microsoft SQL Server 2005 database, and the project involves tracking student attendance records at a university.

I have a table for each class in the uni, and the only field is StudentNumber. Whenever an admin wants to add a new module, a new table is created, and then whenever he wants to add students to that class table he has to currently add each student number to the table individually.

I am looking for a way so that if an admin has a list of student numbers in a text file, he can just submit this text file to my application and the C# will parse this text file and add each individual student number to this table.

Does anybody know any SQL commands that will let me do this or know how I can get the application to ask the user to submit a file?

ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Apr 21 '08

re: Add a list stored in a text file to a SQL Server 2005 database


Quote:

Originally Posted by moorcroft

Hi I am coding an ASP .Net project in C# and am using connection strings to connect to a Microsoft SQL Server 2005 database, and the project involves tracking student attendance records at a university.

I have a table for each class in the uni, and the only field is StudentNumber. Whenever an admin wants to add a new module, a new table is created, and then whenever he wants to add students to that class table he has to currently add each student number to the table individually.

I am looking for a way so that if an admin has a list of student numbers in a text file, he can just submit this text file to my application and the C# will parse this text file and add each individual student number to this table.

Does anybody know any SQL commands that will let me do this or know how I can get the application to ask the user to submit a file?


option 1:
1. Ask for the file name (with path) as parameter in an upload utility that you can create. (catch: the text file has to be on a drive that the server can see)
2. Use BULK INSERT to convert the text file into table.
3. Use T-SQL to update all other table.

option 2:
1. Ask for the file name (with path) as parameter in an upload utility that you can create.
2. Using C#, parse the text file, assuming one row = one record.
3. Do an INSERT for ever row on your text file.

-- CK
Reply