Private Function Save() As Boolean Try Dim dschgs As DataSet = ds.GetChanges(DataRowState.Added + DataRowState.Deleted + DataRowState.Modified) Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("select lotno,isconfirm, confirmuser, confirmdate, eventuser, eventdate from cuttoship", oracleConn) Dim cmbCDDetail As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(da) da.Update(dschgs, "cuttoship") ds.AcceptChanges() Return True Catch ex As Exception Return False End Try End Function
Private Sub btnUnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnConfirm.Click Dim confirmTb As DataTable = gGrid.getCurrData(dgv) Dim r_confirm() As DataRow = confirmTb.Select("s_select='True' and isconfirm='Y'") If r_confirm.Length = 0 Then MessageBox.Show("no seleted data.") Return End If If MessageBox.Show("Do you want to confirm these record?", "Confirm Sure", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.No Then Return Try Dim sql As String = "" Dim time As String = Now.ToString("yyyy-MM-dd HH:mm:ss") Dim row() As DataRow For Each r As DataRow In r_confirm row = ds.Tables("cuttoship").Select("lotno='" + r.Item("lotno") + "'") row(0).BeginEdit() row(0).Item("isconfirm") = "N" row(0).Item("confirmuser") = DBNull.Value row(0).Item("confirmdate") = DBNull.Value row(0).Item("eventuser") = g.gUserId row(0).Item("eventdate") = time row(0).EndEdit() Next If Save() Then MessageBox.Show("Confirm successfully!") Else MessageBox.Show("Confirm failed!") ds.RejectChanges() End If Catch ex As Exception MessageBox.Show("Un Confirm failed!") ds.RejectChanges() End Try End Sub
用dataset保存数据不能存在空的数据,必须用DBNull.Value代替,否则出现“并行违规”的异常。
目标表必须有主键,否则出现“对于不返回任何键列信息的SelectCommand,不支持UpdateCommand 的动态SQL生成”的异常。
vinson