vbs连接sqlserver数据库模糊查询提取数据,使用msgbox全部显示出来

Dim DB 
Dim isSQL
Dim i 
dim tag
dim Describe
dim Addr1
dim Addr2
dim Addr3
dim Addr4
dim str
dim str1
str=""

Set DB = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.RECORDSET") 
i = 0
'tag="P1103B"
tag=inputbox ("请输入Tag")

DB.Open "Driver=SQL Server;server=实例名;Database=数据库名称;uid=sa;pwd=sa的密码;"

isSQL = "select * from IoTable where Tag like '%"&tag&"%'"

Set objRecordSet = DB.Execute(isSQL)

Do While Not objRecordSet.EOF
  
  Addr1 =objRecordSet("列名")+"  "
  Addr2 =Addr1+objRecordSet("列名")+"  "
  Addr3 =Addr2+objRecordSet("列名")+"  "
  if objRecordSet("列名") & "" = ""  then
	str1="null"
	Addr4 =Addr3+str1+ vbcrlf
	str = Addr4+str
  else
	Addr4 =Addr3+objRecordSet("列名")+"  "+ vbcrlf
	str = Addr4+str
  end if	

  
  i = i +1
  
 
 objRecordSet.MoveNext 
 
Loop

if i<=0 then
	msgbox "没有查询到数据"
else
	
	msgbox str
	
end if	


 

你可能感兴趣的:(VBScript)