<summary>////Execute SQL statement, return the number of records affected///</summary>//<param name= "SQLString" >sql statement </param>///<returns> number of records affected </returns> public static int ExecuteSQL (string SQLString, para Ms Oledbparameter[] cmdparms) {using (OleDbConnection connection = new OleDbConnection (connectionString ) {using (OleDbCommand cmd = new OleDbCommand ()) {try {PrepareCommand (cmd, connection, NULL, SQLString, cmdparms); int rows = cmd. ExecuteNonQuery (); Cmd. Parameters.clear (); return rows; } catch (System.Data.OleDb.OleDbException E) {throw new Exce Ption (E.message); }}}}///<summary>///Add a return ID valueTu 2014-12-29//Geovin Du///Http://www.mikesdotnetting.com/article/54/getting-the-identity-o F-the-most-recently-added-record//http://stackoverflow.com/questions/186544/ identity-after-insert-statement-always-returns-0//</summary>//<param name= "SQLString" >< /param>//<param Name= "Identity" ></param>///<param name= "Cmdparms" ></param> <returns></returns> public static int ExecuteSQL (string SQLString, out int identity, params O Ledbparameter[] cmdparms) {using (OleDbConnection connection = new OleDbConnection (connectio nstring) {using (OleDbCommand cmd = new OleDbCommand ()) {TR y {preparecommand (cmd, connection, NULL, SQLString, cmdparms); int rows = cmd. ExecuteNonQuery (); Cmd.commandtext = "SELECT @ @Identity"; identity = (int) cmd. ExecuteScalar (); Cmd. Parameters.clear (); return rows; } catch (System.Data.OleDb.OleDbException E) {throw new Exce Ption (E.message); } } } }
csharp:using OLE DB Getting the identity of the most recently added record