Solved

SQLServer CE identity column

Posted on 2010-11-22
7
831 Views
Last Modified: 2013-12-27
I have just inserted a record into an auto_increment table using the SQLServerCE database.
Keeping in mind that SQLServerCE does not support output parameters, how can
I determine the new value in the autoincrement column for the record I just inserted?

0
Comment
Question by:codefinger
  • 4
  • 3
7 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34186573
you will have to run a second query to fetch the SCOPE_IDENTITY() value ... unfortunately
0
 

Author Comment

by:codefinger
ID: 34188415
I may have the syntax wrong, but I am getting an error that this function is not recognized by SQL Server Compact Edition. My code is attached:

The value of str_sql is "SELECT SCOPE_IDENTITY FROM COMMANDCODES"


Please advise.


Public Function QueryAllAsDataSet(ByVal strsql As String, ByRef lex As LastException) As DataSet

        Dim xds As New DataSet
        Try
            Dim SQLCeAdapter As New System.Data.SqlServerCe.SqlCeDataAdapter(strsql, _conobj.ConnectionString)
            SQLCeAdapter.Fill(xds)
        Catch ex As Exception
            lex.ErrorMessage = ex.Message
            If Not ex.InnerException Is Nothing Then
                lex.ErrorMessage = lex.ErrorMessage & vbCrLf & ex.InnerException.Message
            End If
            _LastError = lex.ErrorMessage
        End Try

        Return xds


    End Function

Open in new window

0
 

Author Comment

by:codefinger
ID: 34188437
sorry, str_sql is "SELECT SCOPE_IDENTITY() FROM COMMANDCODES"

I did not forget the ()  !
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34188523
it's not FROM TABLE ... just SELECT SCOPE_IDENTITY()

you might try SELECT @@IDENTITY  instead
0
 

Author Comment

by:codefinger
ID: 34188661
Same result for SCOPE_IDENTITY() without FROM TABLE in SQL.

I at least get a result for @@IDENTITY,  but it is NULL.


0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 34188695
well, in CE, which is local, as you then are the only session for the db, you will visibly need to do:

select max(id_col) from COMMANDCODES

Open in new window

0
 

Author Closing Comment

by:codefinger
ID: 34188758
That works! Thanks!

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now