sql8 = "select 字段1 from table1 where 字段2='" & Trim(Combo1.Text) & "'"
sql9 = "select 字段1 from table2 where 字段2='" & Trim(Combo2.Text) & "'"
If sql8 <> sql9 Then
   frmMsg.Show
   frmMsg.Text1.Text = "XXXXXXX"
   End If上述代码有问题,我想可能就在"If sql8 <> sql9 Then"这句,我想将两条select查询到的string值进行比较,再弹出提示窗口,请问如何实现?如何将sql8和sql9变成可比较的值呢?

解决方案 »

  1.   

    sql8   =   "select   字段1   from   table1   where   字段2='"   &   Trim(Combo1.Text)   &   "'" 
    sql9   =   "select   字段1   from   table2   where   字段2='"   &   Trim(Combo2.Text)   &   "'" sql8<>sql9永远成立,回为table1<>table2楼主是不是要比较Combo1.text和combo2.text值呀,如果是,直接比较它们就是
      

  2.   

    sql8       =       "select       字段1       from       table1       where       字段2='"       &       Trim(Combo1.Text)       &       "'"   
    sql9       =       "select       字段1       from       table2       where       字段2='"       &       Trim(Combo2.Text)       &       "'"   sql8 <> sql9永远成立,回为table1 <> table2 楼主是不是要比较Combo1.text和combo2.text值呀,如果是,直接比较它们就是---------------------------------------------------------------------------
    我希望比较select语句查询到的table1.字段1和table2.字段1。
      

  3.   

    我的程序思路是:
    combo1选一项,combo2选一项,而后判断combo1所选的这项所在的表中有另一个字段,将这另一个字段与combo2所选的这项所在的表中的另一个字段进行比较,比较后判断是否相同。实际调试中sql8   <>   sql9确实永远成立。   
      

  4.   

    dim sq18 as new recordset
    dim sq19 as new recordset 
    sql8.open "select  字段1   from   table1   where   字段2='"   &   Trim(Combo1.Text)   &   "'",Mconnection 
    sql9.open "select  字段1   from   table2   where   字段2='"   &   Trim(Combo2.Text)   &   "'",Mconnection 
    If   trim(sql8!字段1)   <>   trim(sql9!字段1 )  Then 
          frmMsg.Show 
          frmMsg.Text1.Text   =   "XXXXXXX" 
    End   If 
      

  5.   

    谢谢楼上的caobingyi,可是没有运行成功!请问你的这两句:
    sql8.open   "select     字段1       from       table1       where       字段2='"       &       Trim(Combo1.Text)       &       "'",Mconnection   
    sql9.open   "select     字段1       from       table2       where       字段2='"       &       Trim(Combo2.Text)       &       "'",Mconnection   上面两句结尾的 ",Mconnection"是什么呢?我写上去后就报错若不加",Mconnection"则报错“expected function and variable”,错误标注在“open”上。
      

  6.   

    Mconnection是一个和数据库的链接,只有运行下面的代码后它才能使用
    你可以看看下面的这个代码:
    dim Mconnectionstring as stirng
    Set Mconnection = New Connection
    MconnectionString = "Provider=SQLOLEDB.1;Password='" & Trim(strPasswd) & "';Persist Security Info=true;User ID='" & Trim(strName) & "';Initial Catalog=yinlun;Data Source='" & Trim(strServerAdress) & "'"
    With Mconnection
        .ConnectionString = MconnectionString
        .Open
    End With