|
-
May 7th, 2010, 01:39 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Datagridview to Access Table
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
-
May 7th, 2010, 01:42 AM
#2
Re: Datagridview to Access Table
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.
-
May 7th, 2010, 02:02 AM
#3
Thread Starter
Hyperactive Member
Re: Datagridview to Access Table
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
-
May 7th, 2010, 02:18 AM
#4
Re: Datagridview to Access Table
 Originally Posted by Bongo
I do not use a DataAdapter to get the Data from the CSV
I'm suggesting that you should. You're populating a DataTable anyway and it would be less code with ADO.NET.
Regardless, you DO have a DataTable so, as I said, you can simply use a DataAdapter to save the data to the database exactly as you would any other time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|