I am creating a log in for a patient so they can access information regarding prescriptions etc for a project - (isnt going live)
So I have my patients already created with useame and password and they are linked to their medication through a link table. The log in works and acknowledges that a correct user from the database has logged in - however I want them to be able to access their own details once they are logged in
Imports System.Data.SqlClient
Imports System.Data
Partial Class Pages_Login
Inherits System.Web.UI.Page
Protected Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
Dim patientNo As String
Dim password As String
Dim bAuthethicated As Boolean
patientNo = txtuser.Text
password = txtpassword.Text
bAuthethicated = CheckUser(patientNo, password)
If bAuthethicated Then
lblresult.Text() = "correct"
Else
lblresult.Text() = "Incorrect Student Number and/or Password"
End If
End Sub
Public Function CheckUser(patientNo As String, password As String) As Integer
Dim cmdstring As String = "SELECT * FROM Patient Where Useame=@PATIENTNO AND Password=@PASSWORD"
Dim found = 0
Using co As New SqlCoection("Data Source=(LocalDB)v11.0;AttachDbFilename=C:UsersLauraFinal_projApp_Datasurgerydb.mdf;Integrated Security=True;Coect Timeout=30")
Dim cmd = New SqlCommand(cmdstring, co)
cmd.Parameters.Add("@PATIENTNO", SqlDbType.NChar).Value = patientNo
cmd.Parameters.Add("@PASSWORD", SqlDbType.NChar).Value = password
co.Open()
Dim reader = cmd.ExecuteReader()
While reader.Read()
Session("PatientId") = CInt(reader.Item("PatientId"))
found = CInt(reader.Item("PatientId"))
End While
reader.Close()
End Using
Retu (found)
End Function
End Class
I have notes with the example of a student (mines is patient) however I dont know how to apply this.
Example of session
Try
Dim co As SqlCoection
Dim cmdAs SqlCommand
Dim cmdstring As String = "SELECT * FROM student WHERE "studentnum = @STUDENTNUM"
co = New SqlCoection("Data Source=.SQLEXPRESS; AttachDbFilename=|DataDirectory|University.mdf;Integrated
Security=True;UserInstance=True")
cmd= NewSqlCommand(cmdstring, co)
cmd.Parameters.Add("@STUDENTNUM", SqlDbType.Char).Value = Session("StudID")
co.Open()
Dim myReader As SqlDataReader
myReader= cmd.ExecuteReader(CommandBehavior.CloseCoection)
GridView1.DataSource = myReader
GridView1.DataBind()
co.Close()
Catch ex As Exception
Response.Write("An error has occurred")
End Try

