If the Primary Key is an Autonumber field, you cannot add that to the record, the database adds it for you. If you are handling the primary keys yourself, then yes, you could pull in
the highest primary key value by using the Top value in your query (Select Top 1 ID from Table) similar to below. This isn't really a good idea in a multi user environment
however...
Dim con As New System.Data.SqlClient.SqlConnection("server=YOURSERVER;uid=sa;pwd=******;database=northwind")
Dim daCust As New System.Data.SqlClient.SqlDataAdapter("Select Top 1 EmployeeID From employees", con)
daCust.Fill(DS, "Employees")
TextBox1.DataBindings.Add("Text", DS, "Employees.EmployeeID")
Now IF you need to know the value of the ID of a Newly added record then you would want to use @@Identity from SQL Server or Access
815629 HOW TO: Retrieve the Identity Value While Inserting Records into Access
http://support.microsoft.com/?id=815629
320141 HOW TO: Retrieve an Identity Value from a Newly Inserted Record from SQL
http://support.microsoft.com/?id=320141
Want to know more? Check out the MSDN Library at
http://msdn.microsoft.com or the Microsoft Knowledge Base at
http://support.microsoft.com
Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>
This posting is provided “AS IS”, with no warranties, and confers no rights.
--------------------