Dim da2 As OleDb.OleDbDataAdapter
        Dim cols As Integer = Attendance_QueryDataGridView.ColumnCount
        Dim rows As Integer = Attendance_QueryDataGridView.Rows.Count
        Dim a(cols) As String
        Dim dt As New DataTable("Attendance")

        da2 = New OleDb.OleDbDataAdapter(sql, con)
        da2.Fill(ProjectDataSet, "Attendance")
        Dim NewRow As DataRow
        NewRow = ProjectDataSet.Tables("Attendance").NewRow
        For z = 0 To cols - 1
            a(z) = Attendance_QueryDataGridView.Columns(z).HeaderText
                dt.Columns.Add(a(z))


        Next


        For x = 0 To rows - 2
            NewRow("RainbowID") = Attendance_QueryDataGridView.Item(0, x).Value

           
            For y = 3 To cols
                For z = 3 To cols - 3
                    NewRow(a(z)) = Attendance_QueryDataGridView.Item(y, x).Value

                Next
            Next
        Next
        dt.NewRow()
             da.Update(dt)

>How do i save a query from datagridview back to the database table?

The answer is - DataAdapter and relational class (DataSet/DataTable).

What is a relational class? I tried adding to a new datatable but it then won't let new columns be added to the table in access

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.