如何实现将vsflexgrid中修改的数据反馈到数据库中

 我来答
鈾氶瓏鈾
2016-11-17 · 知道合伙人软件行家
鈾氶瓏鈾
知道合伙人软件行家
采纳数:718 获赞数:1337

向TA提问 私信TA
展开全部
如何实现将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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式