bb = "Provider=SQLOLEDB;User ID=" + userID + " ;PWD=" + passWord    + " ;Initial Catalog=" + dbName + " ;Data Source=" + dbIP
   MsgBox (bb)最后显示的结果是Provider=SQLOLEDB;User ID=sa         后面的字符串都没有显示出来,不知道怎么回事,请高手指点一下

解决方案 »

  1.   

    变量userID中是否含有英文半角的'  ?
      

  2.   

    检测你的userID 是否2个字符
    很有可能你的 
    userID="sa"+chr(0)
      

  3.   

    除了楼上的可能性 把捕捉错误语句 on error goto 或on  error resume next等语句去掉 让
    错误报出来。
      

  4.   

    把所有+改成&试试。我连接字符串都是用&
      

  5.   

    Dim sqlstr As String
              sqlstr = "select cMobilePhone from KzMembers where cEmailAddress in (" + Trim(email) + ")"
              telephone = ""
              '开始连接数据库操作
              Set Conn = New ADODB.Connection
              Set Rs = New ADODB.Recordset
              MsgBox (userName)
              MsgBox (passWord)
              MsgBox (dbName)
              MsgBox (dbIP)
              Dim bb As String, cc As String, dd As String, ee As String
              bb = "Provider=SQLOLEDB;User ID=" + userName + " ;PWD=" + passWord + " ;Initial Catalog=" + dbName + " ;Data Source=" + dbIP
              MsgBox (bb)
    在上面的代码中,一下几行都可以正常获得值
             MsgBox (userName)
              MsgBox (passWord)
              MsgBox (dbName)
              MsgBox (dbIP)
    就是到bb= 这个字符串的时候出错了
      

  6.   

    Dim sqlstr As String
              sqlstr = "select cMobilePhone from KzMembers where cEmailAddress in (" + Trim(email) + ")"
              telephone = ""
              '开始连接数据库操作
              Set Conn = New ADODB.Connection
              Set Rs = New ADODB.Recordset
              MsgBox (userName)
              MsgBox (passWord)
              MsgBox (dbName)
              MsgBox (dbIP)
              Dim bb As String, cc As String, dd As String, ee As String
              bb = "Provider=SQLOLEDB;User ID=" + userName + " ;PWD=" + passWord + " ;Initial Catalog=" + dbName + " ;Data Source=" + dbIP
              MsgBox (bb)
    在上面的代码中,一下几行都可以正常获得值
             MsgBox (userName)
              MsgBox (passWord)
              MsgBox (dbName)
              MsgBox (dbIP)
    就是到bb= 这个字符串的时候出错了
    *******************************************
    以上的代码是在一个
    Public Function backTelephone(email As String, userName As String, passWord As String, dbName As String, dbIP As String) As String 的函数中包括的
    而后面的几个参数是通过从.ini文件中读取过来了
     '开始获取连接数据库的信息
        GetPrivateProfileString "new", "username", "读取文件内容", myini, 255, "c:\loginfo.ini"
         userName = Trim(myini) '用户名
        ' MsgBox (userName)
        GetPrivateProfileString "new", "password", "读取文件内容", myini, 255, "c:\loginfo.ini"
         passWord = Trim(myini) '密码
         ' MsgBox (passWord)
        GetPrivateProfileString "new", "dbname", "读取文件内容", myini, 255, "c:\loginfo.ini"
         dbName = Trim(myini)  '数据库名称
         ' MsgBox (dbName)
        GetPrivateProfileString "new", "ip", "读取文件内容", myini, 255, "c:\loginfo.ini"
         dbIP = Trim(myini)  '数据库服务器IP
         'MsgBox (dbIP)结果就出现了在连接数据库的时候提示的错误
    run-time error '-2147217843(80040e4d)'错误的行是
     bb = "Provider=SQLOLEDB;User ID=" + userName + " ;PWD=" + passWord + " ;Initial Catalog=" + dbName + " ;Data Source=" + dbIP
      

  7.   

    Public Function backTelephone(email As String, userName As String, passWord As String, dbName As String, dbIP As String) As String 的函数中包括的
    而后面的几个参数是通过从.ini文件中读取过来了
    '开始获取连接数据库的信息
    GetPrivateProfileString "new", "username", "读取文件内容", myini, 255, "c:\loginfo.ini"
    userName = Trim(myini) '用户名
    userName=replace(userName,chr(0),"")
    ' MsgBox (userName)
    GetPrivateProfileString "new", "password", "读取文件内容", myini, 255, "c:\loginfo.ini"
    passWord = Trim(myini) '密码
    passWord=replace(passWord,chr(0),"")
    ' MsgBox (passWord)
    GetPrivateProfileString "new", "dbname", "读取文件内容", myini, 255, "c:\loginfo.ini"
    dbName = Trim(myini) '数据库名称
    dbName =replace(dbName ,chr(0),"")
    ' MsgBox (dbName)
    GetPrivateProfileString "new", "ip", "读取文件内容", myini, 255, "c:\loginfo.ini"
    dbIP = Trim(myini) '数据库服务器IP
    dbIP =replace(dbIP ,chr(0),"")
    'MsgBox (dbIP)
      

  8.   

    看来楼主还不会用F8
    vb如果不用f8的话
    很难调错的设置个断点儿,用F8自己跟一下吧
      

  9.   

    MsgBox vbCr & "注册码不正确,请重新输入。" & vbCrLf & vbLf & "如果您想试用本软件可单击『取消』按钮", vbOKOnly + vbInformation, "提示"