Greetings, i have the following problem
I am using VB 2005 and Access 2003
I have on my app a DataGridView filled with data by a CSV file.
Now i need this data transportet in to an existing table in my DB
how can I do this?
Thanks in advance
Printable View
Greetings, i have the following problem
I am using VB 2005 and Access 2003
I have on my app a DataGridView filled with data by a CSV file.
Now i need this data transportet in to an existing table in my DB
how can I do this?
Thanks in advance
Use a DataAdapter to read the data from the CSV file into a DataTable. You can then use another DataAdapter to save the DataTable contents to the database, exactly as though it had come from there in the first place. Just note that the AcceptChangesDuringFill property of the first DataAdapter must be False, so that the rows are left in a state ready to be inserted.
I do not use a DataAdapter to get the Data from the CSV to the DataGridView
Here the code i use to get the data from the CSV to the DataGridView
Code:Dim dt As Data.DataTable
dt = New DataTable
Dim y As Integer = 0
Using sr As New IO.StreamReader(strFileName)
While Not sr.EndOfStream
Dim splitValues() As String = sr.ReadLine.Split(splitChar)
If y = 0 Then
For x As Integer = 0 To splitValues.Length - 1
dt.Columns.Add(splitValues(x))
Next
y = 1
Else
Dim dr As DataRow = dt.NewRow
For x As Integer = 0 To splitValues.Length - 1
dr(x) = splitValues(x)
Next
dt.Rows.Add(dr)
End If
End While
dgvMain.Datasource = dt
End Using