|
-
Mar 24th, 2024, 07:04 AM
#1
Thread Starter
New Member
SQL help pls
Hi there,
I recently started using VB.NET and doing my first VB/SQL project.
I have very basic question.
In VB 6 I used to get the last record result through below SQL (OleDB)
Dim LastRecord as Integer
adoPrimaryRS1.Open "Select * from BUY ORDER BY ID ASC", dB4, adOpenStatic, adLockOptimistic
adoPrimaryRS1.MoveLast
LastRecord = adoPrimaryRS1.Fields!Id
and now I am using SQL Server client, could you please tell me how to achieve above. I am using the below code.
Dim cmd As SqlCommand = New SqlCommand("SELECT TOP 1 ID FROM dbo.Accounts ORDER BY ID DESC", CON)
Dim DA As New SqlDataAdapter(cmd)
Dim DT As New DataTable
Many thanks in advance.
Kh
-
Mar 24th, 2024, 08:39 AM
#2
Re: SQL help pls
Why is it that I already replied to this exact same question in a different forum under a different account?
-
Mar 25th, 2024, 02:21 AM
#3
Re: SQL help pls
 Originally Posted by jmcilhinney
Why is it that I already replied to this exact same question in a different forum under a different account?
This not withstanding: What's so hard about to read the official documentation?
I have no clue about MS SQL, but it took me 2 minutes to find it
https://learn.microsoft.com/en-us/sq...l-server-ver16
Code:
SELECT IDENT_CURRENT ('dbo.Accounts') AS Current_Identity;
Nevermind, that i've never understood the need to know the last inserted Identity.
surrogate ID's should always be opaque to the user.
The only situation you need them, is inserting records into a detail-table where you'd need them for the Foreign key,
and then you just pass it through
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|