Scope Identity in Insert Statement

Nov 28, 2012 at 1:17 PM

Hi 

i want to insert row into table having primary key as identity column

which will return the last inserted value for that primary key column

The general form of my query in MS SqlClient is,

INSERT INTO @TableName

(@ColumnNames)

VALUES (@Values) ;

SELECT SCOPE_IDENTITY()

I write following code to achieve this  

DBProviderImplementation st = DBProviderImplementation.GetImplementation("System.Data.SqlClient");           

DBStatementBuilder statement = st.CreateStatementBuilder(dbData);            statement.BeginFunction(Function.LastID, "Pmkey");         

DBParam paramV = DBParam.ParamWithValue(DbType.String, "Mah");         

DBQuery dbinsert = DBInsertQuery.InsertInto("INFO2").Field("Name")                .Value(paramV);           

dbinsert.BuildStatement(statement);         

int LastPrimaryKeyValue = dbData.ExecuteNonQuery(dbinsert);

Thanks a lot in advance

Nov 28, 2012 at 1:33 PM

Sorry for troubling you i got the answer on http://dynasql.codeplex.com/discussions/360165 this link.

Thanks