I am an avid ASP programer, but I seem to be having problems getting thing done with asp.net. My first asp.net page is a login page where I check to see if the user exists, then if he exists I need to fetch data from two tables so that I can set some session variables. I can't seem to do it. I have several books and have searched this site but still no clue. Maybe I'm hard headed...
Code:
Sub LoginBtn_Click(Sender As Object, E As EventArgs)
If Page.IsValid Then
Dim userDS As New System.Data.DataSet
userDS = MyQueryMethod(UserName.Text, UserPass.Text)
If userDS.Tables(0).Rows.Count = 1 Then
'Here I need to fetch user and agency data from tables and set session variables.
'like - DeptNum, full name, and permissions user has
'then set the session variables like ... session("administartor") = "Yes"
Msg.Text = "Credentials Verified! Welcome."
Else
Msg.Text = "Invalid Credentials: Please try again"
End If
End If
End Sub
Function MyQueryMethod(ByVal userLogin As String, ByVal pass As String) As System.Data.DataSet
Dim connectionString As String = "server='111.11.111.11'; user id='someuserID'; password='SomePassword'; Database='coolDB'"
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT * FROM [Agency], [Users] WHERE (([Users].[UserLogin] = @UserLogin"& _
") AND ([Users].[Pass] = @Pass)) AND ([Users].[DeptID] = [Agency].[DeptID])"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlCommand.Parameters.Add("@UserLogin", System.Data.SqlDbType.NVarChar).Value = userLogin
sqlCommand.Parameters.Add("@Pass", System.Data.SqlDbType.NVarChar).Value = pass
Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function