Get ID

Jelmer

Regular
Joined
Jan 11, 2006
Messages
96
Hello,

I try to find the ID of an inserted row.
this is my code:

Code:
                OleDbConnection Connection = new OleDbConnection();
                Connection = dbase(Connection);
                // Create an OleDb command,  
                OleDbCommand command = new OleDbCommand();
                command.Connection = Connection;
                command.CommandText = "insert into Bedrijven (Bedrijf,Contactpersoon,Adres,Postcode,Plaats,Tel,Mobiel,Fax,Email,Website,kvk,btw,debiteurnr,opmerkingen) values('" + Bedrijf + "','" + Contactpersoon + "','" + Adres + "','" + Postcode + "','" + Plaats + "','" + Tel + "','" + Mobiel + "','" + Fax + "','" + Email + "','" + Website + "','" + KVK + "','" + BTW + "','" + Debiteurnr + "','" + Opmerkingen + " ') ";                                
                command.ExecuteNonQuery();

Is it possible to get the ID of this row after the insert?
 
Well, you've posted in the wrong forum for a start, but the thing you're looking for is the @@IDENTITY (that's if you're using SQL Server):

SELECT @@IDENTITY AS MYID;
 
i use a .mdb file as database...
but there is no possibility to get it with command.id ore something?

Forum.. i know , how to change? :o
 
Sorry - just to elaborate on my previous post...
Visual Basic:
Dim sqlString As String = "select @@IDENTITY as MYID "
Dim localConn As New OleDbConnection(connString)
Dim localComm As New System.Data.OleDb.OleDbCommand(pSQL, localConn)
Dim myId As Int32 = DirectCast(localComm.ExecuteScalar(), Int32)

Paul.
 
Back
Top