I have a simple form for login to an application which needs to pull a a user's information from a database based on variables set on the form and verify that the data matches. I've worked extensively in both VBA and VBscript in the past, and am having trouble making the transition to Visual Basic. I also appear to be using the wrong search terms to find solutions to my problems.
Below is my code. There are two points where Visual Studio is identifying errors for me. Can anyone help me to figure out the correct way to code this?
[tt]
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim UserName As String, Password As String
UserName = Me.txtUsername.Text
Password = Me.txtPassword.Text
Dim constr As String
constr = My.Settings.M2MAydinOtherConnectionString
Dim SQLselect As String
SQLselect = "SELECT Password FROM vwUserDBaccess WHERE UserName = " & UserName & " AND DBid = 46"
Dim ds As DataSet
Dim da As System.Data.SqlClient.SqlDataAdapter
Dim con As System.Data.SqlClient.SqlConnection
con = New System.Data.SqlClient.SqlConnection(constr)
da = New System.Data.SqlClient.SqlDataAdapter(SQLselect, con)
ds = New System.Data.DataSet()
da.Fill(ds)
If IsNull(ds) = True Then
MsgBox("The username is not found in the system. Please try again or contact IT for assistance.", MsgBoxStyle.OkOnly, "Login Failed.")
ElseIf Password <> ds(Password) Then
MsgBox("The password does not match the one in the system for User " & UserName & ". Please contact IT for assistance.")
Else
QCmaster.MdiParent = QualityControl
QCmaster.Show()
Me.Close()
End If
End Sub
[/tt]
I have underlined the errors above.
In the first case, I am attempting to determine if there is actually no record at all matching the criteria. Visual Studio sees IsNull as a variable which should be declared - obviously the IsNull function is not a part of Visual Basic, but I cannot find a comparable process.
In the second case, I am attempting to verify that the record pulled has a password matching what the user entered. Visual Studio informs me that the "Class 'System.Data.DataSet' cannot be indexed because it has no default property." I have no idea how to perform logic on data pulled through the SQL Select statement.
Cheryl dc Kern
Below is my code. There are two points where Visual Studio is identifying errors for me. Can anyone help me to figure out the correct way to code this?
[tt]
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim UserName As String, Password As String
UserName = Me.txtUsername.Text
Password = Me.txtPassword.Text
Dim constr As String
constr = My.Settings.M2MAydinOtherConnectionString
Dim SQLselect As String
SQLselect = "SELECT Password FROM vwUserDBaccess WHERE UserName = " & UserName & " AND DBid = 46"
Dim ds As DataSet
Dim da As System.Data.SqlClient.SqlDataAdapter
Dim con As System.Data.SqlClient.SqlConnection
con = New System.Data.SqlClient.SqlConnection(constr)
da = New System.Data.SqlClient.SqlDataAdapter(SQLselect, con)
ds = New System.Data.DataSet()
da.Fill(ds)
If IsNull(ds) = True Then
MsgBox("The username is not found in the system. Please try again or contact IT for assistance.", MsgBoxStyle.OkOnly, "Login Failed.")
ElseIf Password <> ds(Password) Then
MsgBox("The password does not match the one in the system for User " & UserName & ". Please contact IT for assistance.")
Else
QCmaster.MdiParent = QualityControl
QCmaster.Show()
Me.Close()
End If
End Sub
[/tt]
I have underlined the errors above.
In the first case, I am attempting to determine if there is actually no record at all matching the criteria. Visual Studio sees IsNull as a variable which should be declared - obviously the IsNull function is not a part of Visual Basic, but I cannot find a comparable process.
In the second case, I am attempting to verify that the record pulled has a password matching what the user entered. Visual Studio informs me that the "Class 'System.Data.DataSet' cannot be indexed because it has no default property." I have no idea how to perform logic on data pulled through the SQL Select statement.
Cheryl dc Kern