Basically, I am wanting to get the last userID which is submitted when the user enters their details and clicks the submit button. I have searched the internet and have made changes but still don't understand where i'm going wrong. I used the MAX statement to show the last user ID in the textbox from the user table.my code is shown below:
Protected Sub txtuserID_TextChanged(sender As Object, e As System.EventArgs) Handles txtuserID.TextChanged
Dim strConnection As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=E:\LostPropertyProject\App_Data\LostPropertyDatabase.mdf;Integrated Security=True;User Instance=True"
Dim strConnection As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=E:\LostPropertyProject\App_Data\LostPropertyDatabase.mdf;Integrated Security=True;User Instance=True"
'Establish SQL Connection
Dim con As New SqlConnection(strConnection)
'Open database connection to connect to SQL Server
con.Open()
'Data table is used to bind the resultant data
Dim dtusers As New DataTable()
'Create a new data adapter based on the specified query.
Dim comm As New SqlCommand
comm.CommandText = "SELECT MAX(UserID) FROM tblUser"
comm.Connection = con
Dim MaxUserID As Object = comm.ExecuteScalar()
con.Close()
End Sub
Also, I want the userID to be displayed in the textbox as soon as the page loads. How do I go about doing that?
Would appreciate help. Thank you!