通过vb.net将序列应用于访问的表

时间:2014-02-25 16:51:19

标签: vb.net sequence

有人可以完成以下代码以允许临时表中的列每次递增1(在此示例中从300开始)。我不想使用自动编号,我只想将一个序列应用于列

    Dim conn As OleDbConnection = New OleDbConnection(FileLocations.connectionStringNewDb)
    conn.Open()
    'loop through the temp table starting at the last max test_id from tests and adding 1 to it...
    Dim getTmpTestsSql As String = "SELECT * FROM TESTS_TMP;"
    Dim adapter_tmp As New OleDbDataAdapter(getTmpTestsSql, conn)
    Dim dt_tmp As New DataTable("TESTS_TMP_")
    adapter_tmp.Fill(dt_tmp)
    Dim totalrows As Integer = dt_tmp.Rows.Count
    MsgBox(totalrows)
    Dim sequence_sql As String = "INSERT INTO TEST_TMP VALUES (@TEST_ID)"
    For i = 300 To 300 + totalrows
        Dim create_sequence_cmd As New OleDb.OleDbCommand(sequence_sql, conn)
        create_sequence_cmd.Parameters.AddWithValue("@A_ID", i)
        'move to the next row..................
    Next

    conn.Close()

0 个答案:

没有答案