QTP 查询输入的数据是否已经存在于数据库
Set Conn = CreateObject("ADODB.Connection" )str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=192.168.3.2;DATABASE=svsrmdtest;user id=svsrmd ;password=svsrmd"
Conn.open str
Set Rs = CreateObject ("ADODB.Recordset" )
sql = "select * from t_user where username = '"&DataTable("User_Name",dtGlobalSheet) &"'"
Rs.open sql,conn,1,3
If Rs.eof then
msgbox "do not exist"
Else
msgbox "exist"
End If
代码红色的部分可以实现吗?为什么程序就是一直是msgbox "do not exist"呢? :L研究了一下午也没整明白~ 求助各位大侠! {:3_73:}小女子在此谢谢啦~
Set Conn = CreateObject("ADODB.Connection" )
str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=192.168.3.2;DATABASE=svsrmdtest;user id=svsrmd ;password=svsrmd"
Conn.open str
Set Rs = CreateObject ("ADODB.Recordset" )
mm=DataTable("User_Name",dtGlobalSheet)
sql = "select * from t_user where username = '"&DataTable("User_Name",dtGlobalSheet) &"'"
Rs.open sql,conn,1,3
If Cstr(res(0)) = Cstr(mm) then
msgbox "do not exist"
Else
msgbox "exist"
End If
你的if条件是不对的!
顶下,或者在条件语句里加判断条件。
Set Conn = CreateObject("ADODB.Connection" )
str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=192.168.3.2;DATABASE=svsrmdtest;user id=svsrmd ;password=svsrmd"
Conn.open str
Set Rs = CreateObject ("ADODB.Recordset" )
sql = "select * from t_user"
While not Rst.EOF
n = Rst("user_name").value '从数据表中选定关键字=user_name的列
If n =DataTable("User_Name", dtGlobalSheet)Then
num = num + 1
print " the user has been exist " & num
End If
Rst.MoveNext
Wend 回复 4# superliming
If Cstr(res(0)) = Cstr(mm) then
这个判断条件也有局限,当查询的数据不存在时就会报错了 {:3_77:}不知道为啥,代码今天跑就好使啦,哈哈,谢谢各位鼎力相助哈~
页:
[1]