• 用dataset保存数据注意的问题


    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生成”的异常。

  • 相关阅读:
    rosservice call ERROR:Unable to load type ... Have you typed 'make'
    查看ubuntu版本号
    VirtualBox虚拟机 host/guest 拷贝粘贴,共享剪贴板,安装guest additions
    traffic_light_bag_file 数据集 下载链接
    ubuntu linux double tab
    ubuntu linux查看cpu信息
    ubuntu linux查看硬盘使用量
    ubuntu查看nvidia显卡状态
    ibus
    windows7 屏幕亮图胡乱变化
  • 原文地址:https://www.cnblogs.com/vinsonLu/p/3506922.html
Copyright © 2020-2023  润新知