Andrew Parker
asked on
Storing Userid globally after login
Hi
I have just worked out the login page and it works fine, I now need to store the id of the login for use in the next form.
Private Sub btnOK_click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnOk.Click
Dim SQL As String = "SELECT * FROM Surveyors WHERE SurveyorName = '" & txtLoginName.Text & "' AND Password = '" & txtPassword.Text & "'"
Dim sqlReader As SqlDataReader = RetrieveData(SQL)
If sqlReader.Read Then
globalSurveyorId = 1
MsgBox(globalSurveyorId)
Dim Main As New FormMain()
Main.Show()
Else
MsgBox("Not OK")
End If
sqlReader.Close()
sqlReader = Nothing
End Sub
End Class
Thanks
I have just worked out the login page and it works fine, I now need to store the id of the login for use in the next form.
Private Sub btnOK_click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnOk.Click
Dim SQL As String = "SELECT * FROM Surveyors WHERE SurveyorName = '" & txtLoginName.Text & "' AND Password = '" & txtPassword.Text & "'"
Dim sqlReader As SqlDataReader = RetrieveData(SQL)
If sqlReader.Read Then
globalSurveyorId = 1
MsgBox(globalSurveyorId)
Dim Main As New FormMain()
Main.Show()
Else
MsgBox("Not OK")
End If
sqlReader.Close()
sqlReader = Nothing
End Sub
End Class
Thanks
ASKER
Cool, Works a treat.
That logs me in and sets the SurveyorId, This now populates a ComboBox of all there contracts
Do you know how to pull the contract number from a combobox which is showing Contract name. I ahve at present
Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'globalContractNumber = 423
'DisableFormCloseButton(Me )
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT ContractNumber, ContractName FROM Contracts Where SurveyorId = " & globalSurveyorId
Try
cmd.Connection.Open()
dr = cmd.ExecuteReader
While dr.Read
MyComboBox.Items.Add(dr.Ge tValue(dr. GetOrdinal ("Contract Name")).To String)
End While
Catch ex As SqlException
MessageBox.Show(ex.Message )
Finally
cmd.Connection.Close()
End Try
MyComboBox.SelectedValueCh anged()
Dim val As String
val = MyComboBox.SelectedValue
End Sub
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
'MyComboBox_SelectedValueC hange("Con tractId")
Dim ContractNumber As String
globalContractNumber = ContractNumber
Dim Test As New Formtest()
Test.Show()
End Sub
That logs me in and sets the SurveyorId, This now populates a ComboBox of all there contracts
Do you know how to pull the contract number from a combobox which is showing Contract name. I ahve at present
Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'globalContractNumber = 423
'DisableFormCloseButton(Me
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT ContractNumber, ContractName FROM Contracts Where SurveyorId = " & globalSurveyorId
Try
cmd.Connection.Open()
dr = cmd.ExecuteReader
While dr.Read
MyComboBox.Items.Add(dr.Ge
End While
Catch ex As SqlException
MessageBox.Show(ex.Message
Finally
cmd.Connection.Close()
End Try
MyComboBox.SelectedValueCh
Dim val As String
val = MyComboBox.SelectedValue
End Sub
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
'MyComboBox_SelectedValueC
Dim ContractNumber As String
globalContractNumber = ContractNumber
Dim Test As New Formtest()
Test.Show()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, does the bottom part of the code go into the button or within the try section?
ASKER
sorry, me being doppy, I didnt realise that the tag value should be replace with the "ID" column name
Thanks
Thanks
Public globalSurveyorId As Int16
after the If sqlReader.Read Then
' ID is your field name
globalSurveyorId = sqlReader.Item("ID")
now you can use it whenever you want