作者cawQQ (无痕的旋律)
看板Visual_Basic
标题[.NET] 能帮我看一下VB.NET的问题吗??无法更新
时间Wed Aug 10 00:22:49 2005
修改之後更新会出现问题~
新增之後更心是可以的~
想问一下板上的前辈那边出了问题
两个资料表的表单可以正确新增跟修改
一个资料表的表单可以正确更新~但是修改之後会出问题
以下是我的程式码
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