您的位置:程序门 -> vb ->



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


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb6 我要连接两个字符串 uid=sa和;pwd=111 第二个有分号没法连,请高手帮解决一下
发表于:2007-10-21 11:54:23 楼主
vb6   我要连接两个字符串   uid=sa和;pwd=111   第二个有分号没法连,请高手帮解决一下
发表于:2007-10-21 17:56:421楼 得分:0
a   =   "sa"
b   =   ";111"
c   =   a   &   b
用   "&"   连接就可以了
发表于:2007-10-21 18:22:522楼 得分:0
我都这样连了,还是不行
发表于:2007-10-21 18:32:323楼 得分:0
我把我代码发上来大家研究一下
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"
发表于:2007-10-21 19:51:434楼 得分:0
option   explicit

private   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   "


发表于:2007-10-22 08:23:505楼 得分:0
谢谢回复,问题简单说就是连接符&前面和后面都有分号就连不到一起了.
发表于:2007-10-22 08:36:156楼 得分:0
不会呀。你用   &   连接。不要用   +   ,遇到数字会有歧义。
发表于:2007-10-22 08:55:357楼 得分:0
检查   getinifile   函数是否正确。
调用   server   =   getinifile(sysfile,   section,   "a8")   后   server   的应该仅仅包括正确的内容(比如"a8")而不是带有其它非预期的字符。
发表于:2007-10-22 09:08:188楼 得分:0
问题是这样,&连接符前后都有分号连不到一起,比如
a   =   "aaa;aa"
b   =   ";aaa"
c   =   a   &   b
c结果还是"aaa;aa"
发表于:2007-10-22 09:28:379楼 得分:0
除非有   null   字符,字符串运算是不会解释串内字符意义的。你的   c   是否定长字符串?
发表于:2007-10-22 09:29:5410楼 得分:0
?"a;;;"   &   ";;;b"

a;;;;;;b
发表于:2007-10-22 09:35:5011楼 得分:0
谢谢大家,问题解决了,这个小问题累了我两天。  
我的代码是  
a   =   "driver={sql   server};server=192.168.20.5"  
b   =   ";uid=sa"  
c   =   a   &   b  
刚试了一下,我以前代码放在form_unload里就是不行,刚把代码移到form_load里就可以了,不知啥原因,搞不懂了。
发表于:2007-10-22 09:40:3212楼 得分:0
connectstr   的定义?
是否为常量或定常字符串?
发表于:2007-10-22 10:00:0913楼 得分:0
form_unload   是窗体卸载事件,当然不对了。
发表于:2007-10-22 18:55:4314楼 得分:0
昏迷......
发表于:2007-10-22 19:37:4515楼 得分:0
一起昏~~~~~~~~

边昏边飘走~~~~~
发表于:2007-10-24 15:35:4716楼 得分:0
窗体都unload了,变量当然也阵亡了……


快速检索

最新资讯
热门点击