使用ADO连接数据库之后,可以参考一下代码查询数据并判断数据有效性
sql = "SELECT 型号,出库标记 FROM main"
mainRS.Open sql, maincomm
If mainRS.BOF = True And mainRS.EOF = True Then
MsgBox "库存为空!"
outExcelApp.Workbooks(1).Close
outExcelApp.Quit
Set mainRS = Nothing
maincomm.Close
Set outputcomm=Nothing
MsgBox "退出导入过程!"
outputGrid.Clear
Exit Sub
Else
mainRS.MoveFirst
Do Until (mainRS.EOF)
If mainRS("型号").Value = EType Then
mainOfferHad = True
If mainRS("出库标记").Value = 1 Then
HadType = True
End If
End If
mainRS.MoveNext
Loop
End If
mainRS.Close