none
data does not submit to db RRS feed

  • Question

  • hi, i am trying to import from csv file to sql database using linQ. i get an error message at the submit line. is there anything wrong the way i do it or is in the settings of the sql database.

    thank you.

        Sub ImportFromCSVFile()
    
            Dim filepath As String = "C:\temp\Daily P&L.csv"
    
            Dim lines() As String = System.IO.File.ReadAllLines(filepath)
    
            Dim lineQ = From line In lines _
                        Skip 1 _
                        Let x = line.Split(New Char() {","c}) _
                        Select New Daily_PL() _
                        With {.Date = x(0), .PL = x(1), .VAMI = x(2)}
    
            For Each s In lineQ
                Console.WriteLine(s.Date & " " & s.VAMI)
            Next
            Console.ReadLine()
    
            db.Daily_PL.InsertAllOnSubmit(lineQ)
    
            db.SubmitChanges()
    
        End Sub

     

    Monday, November 28, 2011 2:23 PM

Answers

All replies

  • Friend,

       I dont know the design of your table. But i Assume that you need to save the lines one by one. in that case you may call he InserAllOnSubmit method while you writing the line to the console(appending line by line to the context). If you want to save all the lines together to a single cell, you will have to append it as a string and pass it. Please let us know the exact requirment.

     


    -- Thanks Ajith R Nair
    Monday, November 28, 2011 5:11 PM
  • What is the error message??
    Lloyd Sheen
    Monday, November 28, 2011 5:14 PM
  • Hi gigernorthland;

    Please try the query like this.

    Dim lineQ = (From line In lines _
                 Skip 1 _
                 Let x = line.Split(New Char() {","c}) _
                 Select New Daily_PL() _
                 With {.Date = x(0), .PL = x(1), .VAMI = x(2)}).ToList()
    
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by gigernorthland Wednesday, November 30, 2011 2:00 PM
    Monday, November 28, 2011 6:34 PM
  • Hi gigernorthland,

    Based on your question, here are some links can help you:

    How to read csv file and import its data with Linq

    Import csv file into SQL Server Using Bulk Insert

    Import CSV file and query it with LINQ

    I appreciate if you can provide your table schema, this is so we can help you more effectively.

    Best Regards 


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by gigernorthland Wednesday, November 30, 2011 2:00 PM
    Wednesday, November 30, 2011 2:44 AM
    Moderator