Take the 2-minute tour ×  Here in my code DR.HasRows() returns
True, but DR("LastID") returns DBNUll while SELECT IDENT_CURRENT
('SiteSection') AS 'LastID' works in SQL Management Studio.
__SQLString= "SELECT IDENT_CURRENT ('SiteSection') AS 'LastID'"
Dim DR As SqlDataReader ddConnect() 'It's my custom class that
opens a connection to db, it works DR = ddExecuteReader() If
DR.HasRows() Then     GetLastID = DR("LastID") End If
share|improve this question Why on earth do you care what the
highest ID is? What are you going to do with this information? I
hope you're not going to add 1 to it and make assumptions that
the new value will be the next one inserted... –  Aaron Bertrand
Jan 13 at 2:29 add comment  3 Answers  up vote 4 down vote
accepted  I suspect that the account your .NET application is
using does not have the same permissions as the account you are
using to connect via Management Studio.  That said, I find your
approach questionable at best. What are you planning to do with
the information that come