• CSV file to SQL in ASP.NEt via Schema.ini

    Maxim6m0cj Member

    I need to download a csv file to sql to construct after a graph with visual studio.

    I have all of this running but with integration services, but i want to do the same without the integration services because integration services not exist in sql express.

  • codewithc
    CWC Keymaster

    if you want to construct SQL statements from your CSV file, you can simply open it with a Spreadsheet program like Excel and insert the SQL statements between the data columns. A bit tedious, but it works Smile

    There might be tools to import CSV data if the columns match the tables in your database, but I’ve not familiar with any.

  • Abhey Member

    I have a asp.net page with a graph with the values from sql, and the sql is construct with the csv, this csv refresh every second with new data.

  • SapnaVishwas Member

    You could use awk on a Linux machine, or install one of the free versions available for Windows, and then run a script like this:

    BEGIN {
       print "INSERT INTO [mydb].[mytable]"
       print "   ([fieldname1], [fieldname2], [fieldname3])"
       print "   VALUES"
    }
    {
       print "      (" $0 "),"
    }
    

    using the command

    awk -f myfile.awk myfile.csv
    

    Of course this assumes that the CSV fields map one-to-one with your columns. If they don’t, you can use multiple awk scripts to extract the individual fields and generate multiple SQL scripts.

  • Amit Member

    If you’re on windows look up using a Schema.ini to label the field names and type. Then all you have to do is something like SELECT * INTO tbl FROM [File Path] IN [Name of File] (I can’t remember the exact syntax now). You’ll end up with a table that has been imported nicely from a CSV.

    If you need more info PM me and i’ll reply when I’m at work – I’m doing this kind of thing there at the minute. It’s a very fast and easy way of getting the data into a table.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.