如何实现将vsflexgrid中修改的数据反馈到数据库中
1个回答
展开全部
如何实现将vsflexgrid中修改的数据反馈到数据库中?
'新增和更新单据
Private Sub writeData()
Dim sql, sql1 As String
Dim rstY As New ADODB.Recordset
Dim nn, iRow, iCol As Integer
'更新主表
If blXzXg = "xg" Then
saveSucc = True
sql = "update ckmain set "
sql = sql & "Ckdate ='" & Txt(1).Text & "',"
sql = sql & "Chc ='" & Combo(2).Text & "',"
sql = sql & "custom ='" & Combo(3).Text & "',"
sql = sql & "ywy ='" & Combo(4).Text & "',"
sql = sql & "chlb ='" & Combo(5).Text & "',"
sql = sql & "remark ='" & IIf(Txt(6).Text = "", " ", Txt(6).Text) & "'"
sql = sql & " where ckid='" & Txt(0).Text & "'"
Else
'新增单据判断单号是否有重复
If Me.Txt(0).Text = "" Then Exit Sub
If Not Txt(0).Locked Then
rstY.Open "select ckid from ckmain", cnn, adOpenKeyset, adLockReadOnly, adCmdText
rstY.Filter = rstY.Fields(0).Name & "='" & Me.Txt(0).Text & "'"
If rstY.BOF And rstY.EOF Then
saveSucc = True
Else
MsgBox "该单号已经存在,请重新输入!"
Txt(0).SetFocus
saveSucc = False
rstY.Filter = ""
Set rstY = Nothing
Exit Sub
End If
rstY.Filter = ""
Set rstY = Nothing
End If
'单据单号没有重复,新增一张单
sql = "insert into ckmain values ('" & Txt(0).Text & "',"
sql = sql & "'" & Txt(1).Text & "',"
sql = sql & "'" & Combo(2).Text & "',"
sql = sql & "'" & Combo(3).Text & "',"
sql = sql & "'" & Combo(4).Text & "',"
sql = sql & "'" & Combo(5).Text & "',"
sql = sql & "'" & IIf(Txt(6).Text = "", " ", Txt(6).Text) & "')"
End If
cmm.CommandType = adCmdText
cmm.CommandText = sql
cmm.Execute
If blXzXg = "xz" Then
'新增单据后更新主键
cmm.CommandType = adCmdText
cmm.CommandText = "select ckid from ckmain"
Set rstK = cmm.Execute
rstK.MoveLast
End If
'修改状态先删除子表中原来数据
If blXzXg = "xg" Then
sql = "delete * from ckchild where ckid='" & Me.Txt(0).Text & "'"
cmm.CommandText = sql
cmm.Execute
End If
'更新子表中的数据
With Me.VSFlexGrid1
If .Rows = 1 Then Exit Sub '子表
iRow = 1
iCol = 1
For iRow = 1 To .Rows - 1
If .TextMatrix(iRow, 1) = "" Then Exit For
'新增子表
sql = "insert into ckchild(ckid,matid,matname,matSpc,unit," _
& "price,qty) values ('" & Txt(0).Text & "',"
For iCol = 1 To 4
sql = sql & IIf(.TextMatrix(iRow, iCol) = "", "Null", "'" & .TextMatrix(iRow, iCol) & "'") & ","
Next
sql = sql & IIf(.TextMatrix(iRow, 5) = "", "Null", .TextMatrix(iRow, 5)) & ","
sql = sql & IIf(.TextMatrix(iRow, 6) = "", "Null", .TextMatrix(iRow, 6)) & ")"
cmm.CommandType = adCmdText
cmm.CommandText = sql
cmm.Execute
Next
End With
Call ReadData
End Sub
'新增和更新单据
Private Sub writeData()
Dim sql, sql1 As String
Dim rstY As New ADODB.Recordset
Dim nn, iRow, iCol As Integer
'更新主表
If blXzXg = "xg" Then
saveSucc = True
sql = "update ckmain set "
sql = sql & "Ckdate ='" & Txt(1).Text & "',"
sql = sql & "Chc ='" & Combo(2).Text & "',"
sql = sql & "custom ='" & Combo(3).Text & "',"
sql = sql & "ywy ='" & Combo(4).Text & "',"
sql = sql & "chlb ='" & Combo(5).Text & "',"
sql = sql & "remark ='" & IIf(Txt(6).Text = "", " ", Txt(6).Text) & "'"
sql = sql & " where ckid='" & Txt(0).Text & "'"
Else
'新增单据判断单号是否有重复
If Me.Txt(0).Text = "" Then Exit Sub
If Not Txt(0).Locked Then
rstY.Open "select ckid from ckmain", cnn, adOpenKeyset, adLockReadOnly, adCmdText
rstY.Filter = rstY.Fields(0).Name & "='" & Me.Txt(0).Text & "'"
If rstY.BOF And rstY.EOF Then
saveSucc = True
Else
MsgBox "该单号已经存在,请重新输入!"
Txt(0).SetFocus
saveSucc = False
rstY.Filter = ""
Set rstY = Nothing
Exit Sub
End If
rstY.Filter = ""
Set rstY = Nothing
End If
'单据单号没有重复,新增一张单
sql = "insert into ckmain values ('" & Txt(0).Text & "',"
sql = sql & "'" & Txt(1).Text & "',"
sql = sql & "'" & Combo(2).Text & "',"
sql = sql & "'" & Combo(3).Text & "',"
sql = sql & "'" & Combo(4).Text & "',"
sql = sql & "'" & Combo(5).Text & "',"
sql = sql & "'" & IIf(Txt(6).Text = "", " ", Txt(6).Text) & "')"
End If
cmm.CommandType = adCmdText
cmm.CommandText = sql
cmm.Execute
If blXzXg = "xz" Then
'新增单据后更新主键
cmm.CommandType = adCmdText
cmm.CommandText = "select ckid from ckmain"
Set rstK = cmm.Execute
rstK.MoveLast
End If
'修改状态先删除子表中原来数据
If blXzXg = "xg" Then
sql = "delete * from ckchild where ckid='" & Me.Txt(0).Text & "'"
cmm.CommandText = sql
cmm.Execute
End If
'更新子表中的数据
With Me.VSFlexGrid1
If .Rows = 1 Then Exit Sub '子表
iRow = 1
iCol = 1
For iRow = 1 To .Rows - 1
If .TextMatrix(iRow, 1) = "" Then Exit For
'新增子表
sql = "insert into ckchild(ckid,matid,matname,matSpc,unit," _
& "price,qty) values ('" & Txt(0).Text & "',"
For iCol = 1 To 4
sql = sql & IIf(.TextMatrix(iRow, iCol) = "", "Null", "'" & .TextMatrix(iRow, iCol) & "'") & ","
Next
sql = sql & IIf(.TextMatrix(iRow, 5) = "", "Null", .TextMatrix(iRow, 5)) & ","
sql = sql & IIf(.TextMatrix(iRow, 6) = "", "Null", .TextMatrix(iRow, 6)) & ")"
cmm.CommandType = adCmdText
cmm.CommandText = sql
cmm.Execute
Next
End With
Call ReadData
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |