2014-05-07 54 views
0

我不斷收到此錯誤驗證登錄:system.data.sqlclient.sqlcommand並不能連接到我爲了驗證我的登錄 無法在VB

Imports System.Data.SqlClient 


Public Class Login 
    Dim strSql As String = "Data Source=FILIPA-PC\SQLEXPRESS;Initial Catalog=NIC;Integrated Security=True;" 
    Dim connection As SqlConnection 
    Dim SQL As SqlCommand 
    Dim str As String 
    Dim perfil As String 

    Public Sub BtnLogin_Click(sender As Object, e As EventArgs) Handles BtnLogin.Click 
     Dim username, password As String 
     username = UsernameTextBox.Text 
     password = PasswordTextBox.Text 
     str = "SELECT Tipo_Perfil FROM Perfil INNER JOIN Login ON Perfil.ID_Perfil =Login.ID_Utilizador INNER JOIN Utilizador ON Utilizador.ID_Utilizador=Login.ID_Utilizador WHERE username = '" + username + "' AND passeword = '" + password + "'" 
     connection = New SqlConnection(strSql) 
     connection.Open() 
     SQL = New SqlCommand(str, connection) 
     perfil = "" 
     'perfil = SQL.ExecuteScalar.ToString 
     perfil = Convert.ToString(SQL) 
     MessageBox.Show(perfil) 
     connection.Close() 
     Select Case (perfil) 
      Case "Administrador" 
       Administrador.Show() 
      Case "Utilizador" 
       Utilizador.Show() 
     End Select 


    End Sub 


End Class 

我不知道是什麼問題是,無法連接到我的數據庫來驗證登錄,順便說一句,這些字段都是正確的。沒有錯誤有

+0

'System.Data.SqlClient.SqlCommand'不是錯誤。你應該找到併發布實際的錯誤信息 – ugo

回答

0

有許多的可能性,但沒有看到你得到錯誤信息,這是很難知道:

  1. 是數據庫服務器是否區分大小寫?
  2. 如果是這樣,您是否在連接字符串中使用正確的外殼?
  3. 您在連接字符串中使用「集成安全性」。您是否以訪問服務器和 數據庫的用戶身份運行 應用程序?