Hello: I have an unbound datagrid and I'm trying to save it's contents to my access database.

here's my code thus far:

Dim dt As New DataTable()
            Dim dr As DataRow = Nothing
            For j As Integer = 0 To (Me.DataGridView1.RowCount - 1) - 1
                dr = dt.NewRow()
                If j < 1 Then
                    For k As Integer = 0 To Me.DataGridView1.ColumnCount - 1
                        dt.Columns.Add()
                    Next
                End If

                For i As Integer = 0 To Me.DataGridView1.ColumnCount - 1
                    If Me.DataGridView1.Item(i, j).Value <> "" Then
                        
'it wants to go through all the records...how can i look to see if the cell has been edited or not? 
dr.Item(i) = Me.DataGridView1.Item(i, j).Value.ToString()
                    End If
                Next
                If j > 0 Then
                    dt.Rows.Add(dr)
                End If
            Next

How do I tell it to save to my database?


Any help is truly appreciated.
Thank you very much,
Proctor

Private Sub cmbsd_click()


If cmbsd.Text = "1" Then
q = "select *from std1 where year=" & year.Text & " "
r.CursorLocation = adUseClient

r.Open q, cn, adOpenDynamic, adLockOptimistic
Set DataGrid2.DataSource = r

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.