0

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!

2
Contributors
1
Reply
9
Views
4 Years
Discussion Span
Last Post by JorgeM
0

So exactly what error message are you getting when trying to retreive this info from the DB? I assume that the user ID field is a number?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.