我在Windows窗体中有一个应用程序,并且一切正常,因此现在我在WPF窗体中重新创建了它,以便我可以对其进行更多设计,但是当我重写登录表单的代码并做出是否检查连接的信息时打开它说未声明“ ConnectionState”。
Imports System.Data.SqlClient
Class MainWindow
Private Sub BtnLogin_Click(sender As Object, e As RoutedEventArgs) Handles btnLogin.Click
End Sub
Sub CheckLogin()
Dim RetVal As Integer
Dim conn = New SqlConnection("Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=dbProject;Integrated Security=True")
Using cmd = New SqlCommand("select count(*) from tblLogin where username = @Username and password= @Password;", conn)
cmd.Parameters.Add("@Username", System.Data.SqlDbType.VarChar).Value = txtUsername.Text.Trim
cmd.Parameters.Add("@Password", System.Data.SqlDbType.VarChar).Value = txtPassword.Text.Trim
conn.Open()
If conn.State = ConnectionState.Open Then
RetVal = CInt(cmd.ExecuteScalar)
If RetVal = 1 Then
Else
txtUsername.Clear()
txtPassword.Clear()
txtUsername.Focus()
End If
Else
MessageBox.Show("The connection is not open, contact an administrator!")
End
End If
End Using
End Sub
End Class