I am doing fyp with rfid student attendance system currently. And, I face the problem on saving the database's data.This is the code that i write below:

Dim sqladapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from table_0", conn)
        sqladapter.Fill(ds, "table_0")
        Dim sqladapter_1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from Table_1", conn_1)
        sqladapter_1.Fill(sa, "Table_1")


                sa.Tables(0).Rows(sa.Tables(0).Rows.Count - 1).Item(0) = ds.Tables(0).Rows(i).Item(0)
                sa.Tables(0).Rows(sa.Tables(0).Rows.Count - 1).Item(1) = ds.Tables(0).Rows(i).Item(1)
                sa.Tables(0).Rows(sa.Tables(0).Rows.Count - 1).Item(2) = ds.Tables(0).Rows(i).Item(2)
                flow = True
                DataGridView1.DataSource = sa.Tables(0)

in which sa is student attendance and ds is student list. What code should i added to save the attendance permanently?

Use CommandBuilder to create command objects (Insert,Delete,Update).

Dim sqladapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from table_0", conn)

sqladapter.Fill(ds, "table_0")

'Note that the table_1 must have a primary key.
Dim sqladapter_1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from Table_1", conn_1)

Dim cmb1 as new SqlClient.SqlCommandBuilder(sqladapter_1)

sqladapter_1.Fill(sa, "Table_1")

sa.Tables(0).Rows(sa.Tables(0).Rows.Count - 1).Item(0) = ds.Tables(0).Rows(i).Item(0)
sa.Tables(0).Rows(sa.Tables(0).Rows.Count - 1).Item(1) = ds.Tables(0).Rows(i).Item(1)
sa.Tables(0).Rows(sa.Tables(0).Rows.Count - 1).Item(2) = ds.Tables(0).Rows(i).Item(2)

sqladapter_1.Update(sa,"Table_1")

flow = True
DataGridView1.DataSource = sa.Tables(0)

I have solved the problem. Thanks!!^^

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.