vb6 我要连接两个字符串 uid=sa和;pwd=111 第二个有分号没法连,请高手帮解决一下

解决方案 »

  1.   

    a = "sa"
    b = ";111"
    c = a & b
    用 "&" 连接就可以了
      

  2.   

    我把我代码发上来大家研究一下
    Private Sub Form_Unload(Cancel As Integer)
       Dim server As String, uid As String, pwd As String, database As String, temp As String
       server = getinifile(sysfile, section, "a8")
       uid = getinifile(sysfile, section, "a6")
       pwd = getinifile(sysfile, section, "a7"
       database = getinifile(sysfile, section, "a2")
       connectstr = "driver={SQL Server};server=" & server
       temp = ";uid=" & uid
       MsgBox temp        '这个显示都正常
       connectstr = connectstr & temp
       MsgBox connectstr   '这个显示就没连接到后面
       connectstr = connectstr & temp
       If Len(pwd) > 0 Then connectstr = connectstr & ";pwd=" & pwd
       connectstr = connectstr + ";database=" + database
       MsgBox (connectstr)
    End Sub我要的结果connectstr = "driver={SQL Server};server=192.168.20.5;uid=sa;pwd=****;database=hlyddd"
      

  3.   

    Option ExplicitPrivate Sub Command2_Click()Dim Server As String, Uid As String, Pwd As String, Database As String, Temp As String
    Dim Connectstr As String
        Pwd = "****"
        Server = "192.168.20.5"
        Database = "hlyddd"
        
        Connectstr = "driver={SQL Server};server=" & Server
        Uid = "sa"
        Temp = ";uid=" & Uid
        MsgBox Temp
        Connectstr = Connectstr & Temp
        MsgBox Connectstr    
        'Connectstr = Connectstr & Temp
        
        If Len(Pwd) > 0 Then Connectstr = Connectstr & ";pwd=" & Pwd
        Connectstr = Connectstr + ";database=" + Database
        MsgBox (Connectstr)End Sub我把你的代碼折分後運行,最後的結果和你要的結果一樣"connectstr = "driver={SQL Server};server=192.168.20.5;uid=sa;pwd=****;database=hlyddd""你的:
        pwd = getinifile(sysfile, section, "a7" 
        這行應該在後面加")"    MsgBox Connectstr    
        'Connectstr = Connectstr & Temp
            這第二排的應該注解掉最好加句下"Dim Connectstr As String "
      

  4.   

    谢谢回复,问题简单说就是连接符&前面和后面都有分号就连不到一起了.
      

  5.   

    不会呀。你用 & 连接。不要用 + ,遇到数字会有歧义。
      

  6.   

    检查 getinifile 函数是否正确。
    调用 server = getinifile(sysfile, section, "a8") 后 server 的应该仅仅包括正确的内容(比如"a8")而不是带有其它非预期的字符。
      

  7.   

    问题是这样,&连接符前后都有分号连不到一起,比如
    a = "aaa;aa"
    b = ";aaa"
    c = a & B
    c结果还是"aaa;aa"
      

  8.   

    除非有 Null 字符,字符串运算是不会解释串内字符意义的。你的 C 是否定长字符串?
      

  9.   

    ?"a;;;" & ";;;b"a;;;;;;b
      

  10.   

    谢谢大家,问题解决了,这个小问题累了我两天。 
    我的代码是 
    a = "driver={SQL Server};server=192.168.20.5" 
    b = ";uid=sa" 
    c = a & b 
    刚试了一下,我以前代码放在form_unload里就是不行,刚把代码移到form_load里就可以了,不知啥原因,搞不懂了。
      

  11.   

    connectstr 的定义?
    是否为常量或定常字符串?
      

  12.   

    form_unload 是窗体卸载事件,当然不对了。
      

  13.   

    窗体都unload了,变量当然也阵亡了……