Jelmer Posted July 28, 2006 Posted July 28, 2006 Hello, I try to find the ID of an inserted row. this is my 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? Quote
mandelbrot Posted July 28, 2006 Posted July 28, 2006 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; Quote
Jelmer Posted July 28, 2006 Author Posted July 28, 2006 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 Quote
mandelbrot Posted July 28, 2006 Posted July 28, 2006 Actually, I've just looked on the web, there, and found that it should be the same for Access (someone please correct me if I'm wrong)... http://www.drdev.net/article06.htm ;) Paul Quote
mandelbrot Posted July 28, 2006 Posted July 28, 2006 Sorry - just to elaborate on my previous post... 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.