概述
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生成”的异常。
最后
以上就是眼睛大蜗牛为你收集整理的用dataset保存数据注意的问题的全部内容,希望文章能够帮你解决用dataset保存数据注意的问题所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复