Visual_Basic 板


LINE

修改之後更新会出现问题~ 新增之後更心是可以的~ 想问一下板上的前辈那边出了问题 两个资料表的表单可以正确新增跟修改 一个资料表的表单可以正确更新~但是修改之後会出问题 以下是我的程式码 Private Sub btn_update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_update.Click Dim vbAns As Microsoft.VisualBasic.MsgBoxResult Dim vbDS As postgres_odbc.dsPersonnel Dim vbResult As Boolean Dim vbOpState As OpState vbOpState = Me.JudgeModified vbAns = MsgBoxResult.No Select Case vbOpState Case Module1.OpState.InsertState If (Me.txt_p_id.Text = "NaN") Then MsgBox("未输入身分证字号 !!!", MsgBoxStyle.Critical) Me.txt_p_id.Focus() Return End If If (Me.txt_p_name.Text = "NaN") Then MsgBox("未输入姓名 !!!", MsgBoxStyle.Critical) Me.txt_p_name.Focus() Return End If vbAns = MsgBox("确定新增纪录 ???", MsgBoxStyle.YesNo) vbResult = UpdateDatabasetabasetabase(Module1.OpState.InsertState, "新增纪录中 !!!") Case Module1.OpState.UpdateState vbAns = MsgBox("确定更新记录 ???", MsgBoxStyle.YesNo) vbResult = UpdateDatabasetabasetabase(Module1.OpState.UpdateState, "更新纪录中 !!!") End Select If (vbResult = False) Then Select Case vbOpState Case Module1.OpState.InsertState MsgBox("无法新增纪录 !!!", MsgBoxStyle.Critical, "帐号[" & LOGIN_ACCOUNT & "]") Me.BindingContext(Me.DsPersonelEdit, vbTableName).Position = vbLoc Case Module1.OpState.UpdateState MsgBox("无法更新纪录 !!!", MsgBoxStyle.Critical, "帐号[" & LOGIN_ACCOUNT & "]") End Select Me.DsPersonelEdit.RejectChanges() Me.BindingContext(Me.DsPersonelEdit, vbTableName).CancelCurrentEdit() Else Select Case vbOpState Case Module1.OpState.InsertState vbRecordCount = vbRecordCount + 1 vbRecordIndex = vbRecordCount - 1 Me.ShowStatusBar("新增纪录成功 !!!") Me.cb_Add_Order.Items.Add(Me.txt_p_id.Text) Case Module1.OpState.UpdateState Me.ShowStatusBar("更新纪录成功 !!!") End Select Me.DsPersonelEdit.AcceptChanges() End If End Sub Private Function UpdateDatabasetabasetabase(ByVal vbOpState As OpState, ByVal vbMessage As String) As Boolean Dim vbTransaction As System.Data.Odbc.OdbcTransaction Dim vbDS As postgres_odbc.dsPersonnel Dim vbDSDeleted As postgres_odbc.dsPersonnel Me.ShowStatusBar(vbMessage) Select Case vbOpState Case Module1.OpState.InsertState Case Module1.OpState.DeleteState '复制记录集(Dataset)为暂存记录集 vbDSdeleted vbDSDeleted = New postgres_odbc.dsPersonnel vbDSDeleted = Me.DsPersonelEdit.Copy End Select Me.BindingContext(Me.DsPersonelEdit, vbTableName).EndCurrentEdit() Select Case vbOpState Case Module1.OpState.DeleteState '删除暂存记录集 vbDSdeleted记录集 vbDSDeleted.tbl_personnel.Rows(Me.BindingContext(Me.DsPersonelEdit, vbTableName).Position).Delete() vbDS = CType(vbDSDeleted.GetChanges, postgres_odbc.dsPersonnel) Case Else vbDS = CType(Me.DsPersonelEdit.GetChanges, postgres_odbc.dsPersonnel) End Select Try Me.OdbcConnection1.Open() Catch ex As Exception MsgBox("Connection Error:" & ex.Message) Return False End Try vbTransaction = Me.OdbcConnection1.BeginTransaction() Me.OdbcDataAdapter1.UpdateCommand.Transaction = vbTransaction Me.OdbcDataAdapter1.DeleteCommand.Transaction = vbTransaction Me.OdbcDataAdapter1.SelectCommand.Transaction = vbTransaction Me.OdbcDataAdapter1.InsertCommand.Transaction = vbTransaction Try Select Case vbOpState Case Module1.OpState.UpdateState Me.OdbcDataAdapter1.Update(vbDS, vbTableName) Case Module1.OpState.DeleteState Me.OdbcDataAdapter1.Update(vbDS, vbTableName) Case Module1.OpState.InsertState Me.OdbcDataAdapter1.Update(vbDS, vbTableName) End Select vbTransaction.Commit() '交易成功传回True Return True Catch ex As Exception vbTransaction.Rollback() '交易失败传回False Return False Finally Me.OdbcConnection1.Close() End Try End FunctionPrivate Function UpdateDatabasetabasetabase(ByVal vbOpState As OpState, ByVal vbMessage As String) As Boolean Dim vbTransaction As System.Data.Odbc.OdbcTransaction Dim vbDS As postgres_odbc.dsPersonnel Dim vbDSDeleted As postgres_odbc.dsPersonnel Me.ShowStatusBar(vbMessage) Select Case vbOpState Case Module1.OpState.InsertState Case Module1.OpState.DeleteState '复制记录集(Dataset)为暂存记录集 vbDSdeleted vbDSDeleted = New postgres_odbc.dsPersonnel vbDSDeleted = Me.DsPersonelEdit.Copy End Select Me.BindingContext(Me.DsPersonelEdit, vbTableName).EndCurrentEdit() Select Case vbOpState Case Module1.OpState.DeleteState '删除暂存记录集 vbDSdeleted记录集 vbDSDeleted.tbl_personnel.Rows(Me.BindingContext(Me.DsPersonelEdit, vbTableName).Position).Delete() vbDS = CType(vbDSDeleted.GetChanges, postgres_odbc.dsPersonnel) Case Else vbDS = CType(Me.DsPersonelEdit.GetChanges, postgres_odbc.dsPersonnel) End Select Try Me.OdbcConnection1.Open() Catch ex As Exception MsgBox("Connection Error:" & ex.Message) Return False End Try vbTransaction = Me.OdbcConnection1.BeginTransaction() Me.OdbcDataAdapter1.UpdateCommand.Transaction = vbTransaction Me.OdbcDataAdapter1.DeleteCommand.Transaction = vbTransaction Me.OdbcDataAdapter1.SelectCommand.Transaction = vbTransaction Me.OdbcDataAdapter1.InsertCommand.Transaction = vbTransaction Try Select Case vbOpState Case Module1.OpState.UpdateState Me.OdbcDataAdapter1.Update(vbDS, vbTableName) Case Module1.OpState.DeleteState Me.OdbcDataAdapter1.Update(vbDS, vbTableName) Case Module1.OpState.InsertState Me.OdbcDataAdapter1.Update(vbDS, vbTableName) End Select vbTransaction.Commit() '交易成功传回True Return True Catch ex As Exception vbTransaction.Rollback() '交易失败传回False Return False Finally Me.OdbcConnection1.Close() End Try End Function -- 我的马子相簿喔... http://www.wretch.cc/album/homb --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.170.54.13
1F:→ linmic:通常这麽长没人有耐性看@@ 220.139.151.70 08/10
2F:→ cawQQ:写的比较严仅....所以长了点@@" 218.170.54.13 08/10
3F:推 fumizuki:该换行的地方没换行? 210.58.156.43 08/10
4F:→ fumizuki:你贴上来的程式码很乱 210.58.156.43 08/10
5F:推 cawQQ:已经解决了...是资料库的字元问题..怪怪= =" 218.170.67.166 08/11







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:WOW站内搜寻

TOP