mshflexgrid 数据上传到SQL
我用MSHFLEXGRID批量输入资料,最后提交,上传到SQL B表中, 条件是
MSFHFLEXGRID 单元格1列的资料,在表A中要存在,在表B中要不存在 并且上传完后,上传上去的,资料在MSHFLEXGRID 中消失,只存在那些条件异常 没上传到SQL 的记录
barcode 是条码,MSHFLEXGRID(I,1) 是条玛+数量序列号
Case "save"
Dim js As Integer
Dim rs2 as new recordset
Dim rs4 as new recordset
dim Djls as integer
If js = MS1.Rows - 2 Then
MsgBox "没有要保存的数据!", , "提示窗口"
Exit Sub
End If
For i = 1 To MS1.Rows - 2
rs4.Open "select gch,tdh,bh,barcode from printdata where barcode='" + Left(MS1.TextMatrix(i, 1), Len(MS1.TextMatrix(i, 1)) - InStr(StrReverse(MS1.TextMatrix(i, 1)), "-")) + "'", cnn, adOpenDynamic, adLockBatchOptimistic
If rs4.RecordCount > 0 Then
rs2.Open "select * from scandata where barcode='" + MS1.TextMatrix(i, 1) + "' and stationname='" + Combo1 + "'", cnn, adOpenDynamic, adLockReadOnly
If IsNull(MS1.TextMatrix(i, 1)) = False And rs2.EOF Then
cnn.Execute ("insert into scandata(barcode,stationname,scanop,scandate,scantime)Values ( '" + Trim(MS1.TextMatrix(i, 1)) + "','" + Trim(Combo1) + "','" + Trim(Label4) + "','" & Date & "','" & Time & "')")
Djls = Djls + 1
End If
rs2.Close
Next i
cnn.Close
MsgBox "共有『" + CStr(Djls) + "』记录数被导入"
谢谢!
barcode MSHFLEXGRID
[解决办法]
INSERT INTO 表2
SELECT ............ WHERE NOT EXISTS (SELECT 1 FROM 表2 S WHERE S.主键=.....)
试试这句话,这样子简洁