将数据表保存到两个数据库中

时间:2012-08-13 09:14:39

标签: vb.net datatable

我有代码将mydatatable中的信息保存到数据库中,也存储到我的审计文件中我使用下面的代码。但是代码的第一部分工作得很好但第二部分没有完成工作。为什么相同的代码不适用于另一个数据库。它没有将数据表插入审计文件

 '**************************************************************************************************************************************************
    '*********************  SAVE PRODUCT RAW MATERIAL DETAILS IN THE GRIDVIEW  ******************************************************

    Dim myConn As OleDbConnection = frmLogIn.Conn
    Dim oledbCmdBuilder As OleDbCommandBuilder
    Dim changes As DataTable

    Dim sql As String = "select * from ProductRawMaterial"
    Dim oledbAdapter As OleDbDataAdapter = New OleDbDataAdapter(sql, myConn)
    'Try
    oledbCmdBuilder = New OleDbCommandBuilder(oledbAdapter)
    changes = myTable.GetChanges()
    oledbCmdBuilder.ConflictOption = ConflictOption.OverwriteChanges

    If changes IsNot Nothing Then
        oledbAdapter.Update(myTable)
    End If
    'myTable.AcceptChanges()
    myConn.Close()

    'Catch ex As Exception
    '    MsgBox(ex.ToString)
    'End Try
    '***************************************************************************************************************************************************
    '*********************************************************    SAVING TO AUDIT   ****************************************************************

    Dim myKonn As OleDbConnection = frmLogIn.Connn
    Dim oledbCmdBuilderAudit As OleDbCommandBuilder
    'Dim changes As DataTable

    Dim sqlAudit As String = "select * from ProductRawMaterial"
    Dim oledbAdapterAudit As OleDbDataAdapter = New OleDbDataAdapter(sqlAudit, myKonn)
    'Try
    oledbCmdBuilderAudit = New OleDbCommandBuilder(oledbAdapterAudit)
    'changes = myTable.GetChanges()
    oledbCmdBuilderAudit.ConflictOption = ConflictOption.OverwriteChanges

    If changes IsNot Nothing Then
        oledbAdapterAudit.Update(myTable)
    End If
    myTable.AcceptChanges()
    myKonn.Close()

    'Catch ex As Exception
    '    MsgBox(ex.ToString)
    'End Try

0 个答案:

没有答案