0

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?

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by noname1015
1

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)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.