0

I have the following VB.NET code to copy data from a .csv file to a data table (dt). The columns are F1,F2,F3,F4. I want to copy the data from the data table (dt) to a sql table (ontledings) with the following columns : BLOk,KULTIVAR,DATUM and SUIKER.

    Private Sub OesskattingsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OesskattingsToolStripMenuItem.Click

    Dim folder = "C:\Users\Administrator\Desktop\Skedulering\EZY Wine Data\"
    Dim CnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & folder & ";Extended Properties=""text;HDR=No;FMT=Delimited"";"
    Dim dt As New DataTable
    Using Adp As New OleDbDataAdapter("select * from labanal2.csv", CnStr)
        Adp.Fill(dt)
    End Using



    Dim strsql As String = "insert into ontledings (BLOK,KULTIVAR,DATUM,SUIKER) values (@F1,@KF2,@F3,@SF4)"

    Dim SqlconnectionString As String = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Administrator\Desktop\Skedulering\Skedulering\Skedulering\SkeduleringDatabasis.mdf;Integrated Security=True"

    Using connection As New SqlClient.SqlConnection(SqlconnectionString)
        Dim cmd As New SqlClient.SqlCommand(strsql, connection)
        With cmd.Parameters
            .Add("@F1", SqlDbType.VarChar, 50, "BLOK")
            .Add("@F2", SqlDbType.VarChar, 50, "KULTIVAR")
            .Add("@F3", SqlDbType.Date, 50, "DATUM")
            .Add("@F4", SqlDbType.Decimal, 50, "SUIKER")
        End With

        Dim adapter As New SqlClient.SqlDataAdapter()

        adapter.InsertCommand = cmd

        Dim iRowsInserted As Int32 = adapter.Update(dt)

    End Using
    MsgBox("Finished")
End Sub

However when I execute the code, it runs without errors, but no data is inserted into the sql table. I have tried and read numerous questions and answers and are now truly confused.

Any help would be much appreciated.

Gideon
  • 313
  • 1
  • 2
  • 18

0 Answers0