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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moorcroft
    New Member
    • Mar 2008
    • 57

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

    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
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    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

    Comment

    Working...