从Gird控件中获取大量数据然后往数据库中保存,如何SQL语句改成为以DECLARE的批处理保存方式使速更快
Dim strSQL As String
Dim cBuscode As String '本单据单号
Dim GirRows As Integer
Dim MModel As String
Dim MName As String
Dim ModelCode As String
Dim BodyCode As String
Dim EngCode As String
Dim EngModel As String
cBuscode = Me.ecode.Text
If cBuscode = vbNullString Then
MsgBox "单号不能为空!", vbInformation + vbOKOnly, "提示"
Exit Sub
End If
R = GirRows - 1 'Gird控件行数
If R <= 0 Then
MsgBox "没有数据可以保存汇总!", vbInformation + vbOKOnly, "提示"
Exit Sub
End If
Do While R > 0
MModel = Trim$(Me.SGrid.TextMatrix(R, 1))
MName = Trim$(Me.SGrid.TextMatrix(R, 2))
ModelCode = Trim$(Me.SGrid.TextMatrix(R, 3))
BodyCode = Trim$(Me.SGrid.TextMatrix(R, 4))
EngCode = Trim$(Me.SGrid.TextMatrix(R, 5))
EngModel = Trim$(Me.SGrid.TextMatrix(R, 6))
'***********验证数据是否合法,然后保存*********
If MModel = vbNullString Then
MsgBox "存货编码不能为空,“" & MModel & "”或存货编号有错!", vbInformation + vbOKOnly, "提示"
Exit Do
End If
If BodyCode = vbNullString Or Len(BodyCode) <> 17 Then
MsgBox "身体号不能为空,“" & BodyCode & "”或不等于17位!", vbInformation + vbOKOnly, "提示"
Exit Do
End If
If EngCode = vbNullString Or Len(EngCode) <> 9 Then
MsgBox "机号不能为空,“" & EngCode & "”或不等于9位!", vbInformation + vbOKOnly, "提示"
Exit Do
End If
'如何将下边的这个SQL语句改成为以DECLARE(查看过帮助了看得不是很明白)的批处理保存方式使速更快,谢谢!
strSQL = "INSERT INTO TableProductIN (cBuscode, Modle, ModleName, ModleCode, BodyCode, EngineCode, EngineName) VALUES ('" & cBuscode & "','" & MModel & "','" & MName & "','" & ModelCode & "','" & BodyCode & "','" & EngCode & "','" & EngModel & "')"
'p_cn这ADO连接
prs.Open strSQL, p_cn, adOpenStatic, adLockReadOnly
If prs.State = adStateOpen Then prs.Close
R = R - 1
Loop

