Solved

VB.net SQL selecting the last record appended

Posted on 2011-09-09
3
279 Views
Last Modified: 2012-05-12
Hi.
In Vb.net I am appending data to a SQL database using the following code
    oSQL = "Insert Into Table1 ([oDate],[oText], [oNumber]) Select '" & oDate & "' as Expr1, '" & oText & "' as Expr2, " & oNumber & " as Expr3"
I want to select the last row appended to make sure that it actually was. Since the ID field is automatically generated this is a little tricky
0
Comment
Question by:murbro
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
DrewKjell earned 500 total points
ID: 36510351
SELECT MAX(<YOURIDFIELD>)
FROM Table1

Or if it's an Identity field you can look into SCOPE_IDENTITY().

What exactly are you wanting to do with selecting the record back?

Drew
0
 

Author Closing Comment

by:murbro
ID: 36510521
Great answer. Didn't expect that. Thanks
0
 

Author Comment

by:murbro
ID: 36510533
To clarfy the MAX part sufficed
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question