VB在连接SQL SERVER时出错.下面是我的代码:
Private Sub cmdLogin_Click()
  UID = txtUserName.Text
  PWD = txtPassword.Text
  If db.ConnectionString <> "" Then
     MsgBox "请先注销再登录!", , "登录"
     Unload Me
     Exit Sub
  End If
  db.ConnectionString = "Provider=SQLOLEDB.1;" & _
                        "persist security Info=false;" & _
                        "user ID=" & UID & _
                        "passward=" & PWD & _
                        ";initial catalog=jxcdatabase;" & _
                        "Data Source=txd"
  db.Open
在ODBC中我做了一个数据源,在"系统DSN"中有一个TXD数据源,在运行时,到了DB,OPEN
就不运行了,各位高手请问这是什么原因呀?

解决方案 »

  1.   

    你這樣的連接是ado連接,我沒有說錯吧。。我暈你用adodc控件連接,然後把生成的字符copy下來就是你想要的代碼了。
      

  2.   

    Private Sub cmdLogin_Click()
      UID = txtUserName.Text
      PWD = txtPassword.Text
      If db.ConnectionString <> "" Then
         MsgBox "请先注销再登录!", , "登录"
         Unload Me
         Exit Sub
      End If
      '少了一个分号.
      db.ConnectionString = "Provider=SQLOLEDB.1;" & _
                            "persist security Info=false;" & _
                            "user ID=" & UID &  _
                            ";passward=" & PWD & _
                            ";initial catalog=jxcdatabase;" & _
                            "Data Source=txd"
      db.Open