 |
|
asp.net ต้องการ Update ลงฐานข้อมูล Foxpro ไม่สามารถ Update ลงฐานข้อมูลได้ ต้องทำอย่างไรครับ |
|
 |
|
|
 |
 |
|
ใช้ asp.net ต้องการ Update ลงฐานข้อมูล Foxpro แต่ไม่สามารถ Update ลงฐานข้อมูลได้ โดยจะฟ้องว่า "ไม่สามารถ Update ลงฐานข้อมูลได้ อาจมีข้อมูลซ้ำ" ตามCode ที่ให้ ไม่ทราบว่าต้องแก้ไขอย่างไรครับ ทั้งๆที่ได้แชร์โฟลเดอร์ของ Database แล้ว Code ดังกล่าวดัดแปลงมาจาก ซีดีสอนของอ.ธงชัย แต่ถ้าลองใช้ฐานข้อมูลที่เป็น Access สามารถ Update ได้ครับ
Code (VB.NET)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim fName As String = "FIL0001"
Dim DV2 As New DataView(DT.Table)
DV2.RowStateFilter = DataViewRowState.ModifiedCurrent
Dim drv As DataRowView
Dim c1 As New MISAccess("c:\Database\" & fName & ".dbf")
Dim strsql As String = ""
strsql = "update " & fName & " set mark = @P1 where code = @P2"
Dim TX As OleDbTransaction
Dim Cn As New OleDbConnection(c1.Strcon)
Dim Cmd As New OleDbCommand(strsql, Cn)
c1.CreateParam(Cmd, "MN")
Cn.Open()
TX = Cn.BeginTransaction
Cmd.Transaction = TX
Dim Fail As Boolean = False
For Each drv In DV2
Cmd.Parameters("@P1").Value = drv("mark")
Cmd.Parameters("@P2").Value = drv("code")
Try
Cmd.ExecuteNonQuery()
Catch
Fail = True
Exit For
End Try
Next
If Fail = True Then
TX.Rollback()
Label1.Text = "ไม่สามารถ Update ลงฐานข้อมูลได้ อาจมีข้อมูลซ้ำ"
Else
TX.Commit()
Label1.Text = "Update ลงฐานข้อมูลเรียบร้อยแล้ว"
DT.Table.AcceptChanges()
End If
Label1.Visible = True
Cn.Close()
grdDTS2.CurrentPageIndex = 0
grdDTS2.EditItemIndex = -1
Me.MyGridBind()
End Sub
Public Sub CreateParam(ByRef Cmd As OleDbCommand, ByVal StrType As String)
'T:Text, M:Memo, Y:Currency, D:Datetime, I:Integer, S:Single, B:Boolean
Dim i As Integer
Dim j As String
For i = 1 To Len(StrType)
j = UCase(Mid(StrType, i, 1))
Dim P1 As New OleDbParameter()
P1.ParameterName = "@P" & i
Select Case j
Case "T"
P1.OleDbType = OleDbType.VarChar
Case "M"
P1.OleDbType = OleDbType.LongVarChar
Case "Y"
P1.OleDbType = OleDbType.Currency
Case "M"
P1.OleDbType = OleDbType.Char
Case "N"
P1.OleDbType = OleDbType.Numeric
End Select
Cmd.Parameters.Add(P1)
Next
End Sub
Tag : ASP
|
|
 |
 |
 |
 |
Date :
2012-11-23 17:42:48 |
By :
Application3 |
View :
1034 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้า Error นั้น น่าจะเป็นที่ Key ซ้ำ หรือเปล่าครับ 
|
 |
 |
 |
 |
Date :
2012-11-25 20:54:00 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|