title: Get last UserID from SqlServer to textbox control
body: <p>I have a table <code>customers</code> where each cust has <code>UserID</code> as <strong>"A000"</strong> now I need to get the <strong>last</strong> entered <strong><code>ID</code></strong> from the database and display it in my textbox.</p>
  
  <p>Can anyone suggest me how do I do this?</p>
  
  <p>As I have seen many articles describing about </p>
  
  <pre><code>SELECT @@IDENTITY
  SELECT SCOPE_IDENTITY()
  SELECT IDENT_CURRENT('TableName')
  </code></pre>
  
  <p>but unable to know where to use it correctly.</p>
  
  <p>And here is how I'm doing it :</p>
  
  <pre><code> Dim strConnection As String = "Data Source=.\SqlExpress;Initial Catalog=Subscription;Integrated Security=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 da As New SqlDataAdapter("SELECT MAX(UserID) FROM Customers", con)
   Dim cmd As New SqlCommandBuilder(da)
   da.Fill(dtusers)
   con.Close()
  </code></pre>