private void adapter_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) { int id = 0; using (OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY", adapter.Connection)) { id = (int)cmd.ExecuteScalar(); } e.Row["ID"] = id; } }
private void daProject_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", ctnABCTestProject); if (e.StatementType == StatementType.Insert) { newID = (int)idCMD.ExecuteScalar(); e.Row["ProjectID"] = newID; } }
private void daOwner_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", Green); if (e.StatementType == StatementType.Insert) { newID = (int)idCMD.ExecuteScalar(); e.Row["OwnerID"] = newID; } }
//Functions to access the new value of each table key field private void daRaceCourse_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", ctnNorthIslandRacing); if (e.StatementType == StatementType.Insert) { newID = (int)idCMD.ExecuteScalar(); e.Row["RaceCourseID"] = newID; } }
private void daServiceTypeEquipment_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { //int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", Green); if (e.StatementType == StatementType.Insert) { //newID = (int)idCMD.ExecuteScalar(); //e.Row["ServiceTypeID"] = newID; } }
//automaticly create ID to stop the ID errors private void daCandidate_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", ctnLookingGlass); if (e.StatementType == StatementType.Insert) { newID = (int)idCMD.ExecuteScalar(); e.Row["CandidateID"] = newID; } }
void daApp_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) { int id = 0; using (OleDbCommand cmd = new OleDbCommand("SELECT DMAX('UniqueID', 'Appointments')", daApp.Connection)) { id = Convert.ToInt32(cmd.ExecuteScalar()); } e.Row["UniqueID"] = id; } }
private void EventAdaptor_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { int newId = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", oleDbConnection1); if (e.StatementType == StatementType.Insert) { newId = (int)idCMD.ExecuteScalar(); e.Row["EventID"] = newId; } }
private void daEventRegister_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", ctnKai); if (e.StatementType == StatementType.Insert) { newID = (int)idCMD.ExecuteScalar(); e.Row["RegistrationID"] = newID; } }
// </Snippet1> // <Snippet2> private static void OnRowUpdated( object sender, OleDbRowUpdatedEventArgs e) { // Conditionally execute this code block on inserts only. if (e.StatementType == StatementType.Insert) { OleDbCommand cmdNewID = new OleDbCommand("SELECT @@IDENTITY", connection); // Retrieve the Autonumber and store it in the CategoryID column. e.Row["CategoryID"] = (int)cmdNewID.ExecuteScalar(); e.Status = UpdateStatus.SkipCurrentRow; } }
static void OnRowUpdated(object sender, OleDbRowUpdatedEventArgs e) { if (e.StatementType == StatementType.Insert) { // Retrieve the identity value OleDbCommand cmdNewId = new OleDbCommand("Select @@IDENTITY", e.Command.Connection); e.Row["PersonID"] = (Int32)cmdNewId.ExecuteScalar(); // After the status is changed, the original values in the row are preserved. And the // Merge method will be called to merge the new identity value into the original DataTable. e.Status = UpdateStatus.SkipCurrentRow; } }
public void minusOneSolver(string ID, OleDbRowUpdatedEventArgs e) { //include a variable and a command to retrieve the identity value from the access database int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", ctnBookBrokers); if (e.StatementType == StatementType.Insert) { //retrive the identity value and store it in the ID column newID = (int)idCMD.ExecuteScalar(); e.Row[ID] = newID; } }
///<Summary> method : dacase_RowUpdated /////to solve the -1 problem when delete data ///</Summary> private void dacase_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", ctnbigeye); if (e.StatementType == StatementType.Insert) { // Retrieve the identity value and // store it in the CaseID column. newID = (int)idCMD.ExecuteScalar(); e.Row["CaseID"] = newID; } }
private void daOwner_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", CntGreen); if (e.StatementType == StatementType.Insert) { // Retrieve the identity value and // store it in the TreatmentID column. newID = (int)idCMD.ExecuteScalar(); e.Row["OwnerID"] = newID; } }
private void Adapter_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { if ((e.Status == UpdateStatus.Continue) && e.StatementType == StatementType.Insert) { int newID = 0; OleDbCommand cmdGetId = new OleDbCommand("SELECT @@IDENTITY", e.Command.Connection); newID = (int)cmdGetId.ExecuteScalar(); newDataId = newID; if (newID == 0) { MessageBox.Show("获取ID值错误!"); } } }
//vehicle private void vehicleDataAdapter_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { // initialize a variable and a command to retrieve the last identity value created in the vehicle table. int newID = 0; // @@IDENTITY returns the last identity value (primary key) that was generated by a statement. OleDbCommand getLastIdentityCommand = new OleDbCommand("SELECT @@IDENTITY", greenConnection); if (e.StatementType == StatementType.Insert) { // if the statement was an insert statement newID = (int)getLastIdentityCommand.ExecuteScalar(); e.Row["VehicleID"] = newID; } }
private void daOwner_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { // Include a variable and a command to retrieve // the identity value from the Access database. int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", ctnGlendene); if (e.StatementType == StatementType.Insert) { // Retrieve the identity value and store it in the OwnerID column. newID = (int)idCMD.ExecuteScalar(); e.Row["OwnerID"] = newID; } }
private void daServiceType_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { //include a variable and a command to retrieve // the identity value from the access database. int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", ctnGreens); if (e.StatementType == StatementType.Insert) { //retrieve the identity value and store it in the service type column. newID = (int)idCMD.ExecuteScalar(); e.Row["ServiceTypeID"] = newID; } }
private void daTreatment_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { //Include a variable and a command to retrive //the identity value from the Access database int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", CtnGlendene); if (e.StatementType == StatementType.Insert) { //retrive the identity value //store it in the TreatmentID newID = (int)idCMD.ExecuteScalar(); e.Row["TreatmentID"] = newID; } }
private void daVendor_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { // Include a variable and a command to retrieve // the identity value from the Access database. int newID = 0; OleDbCommand idCMD = new OleDbCommand("Select @@IDENTITY", ctnBookBrokers); if (e.StatementType == StatementType.Insert) { // Retrieve the identity value and // store it in the TreatmentID column. newID = (int)idCMD.ExecuteScalar(); e.Row["VendorID"] = newID; } }
private void daBook_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { // Include a variable and a command to retrieve // the identity value from the access database int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", ctnBookBroker); if (e.StatementType == StatementType.Insert) { // Retrieve the identity value and //store it the BookID Column newID = (int)idCMD.ExecuteScalar(); e.Row["BookID"] = newID; } }
/// <summary> /// Get the new primary key on added rows /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void daPhones_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) { OleDbCommand cmd = new OleDbCommand("Select @@Identity", dbConn); e.Row["PhoneKey"] = cmd.ExecuteScalar(); e.Row.AcceptChanges(); } // Ignore deletions that don't find their row. The cascade delete took care of them already. if (e.StatementType == StatementType.Delete && e.RecordsAffected == 0 && e.Status == UpdateStatus.ErrorsOccurred) { e.Status = UpdateStatus.Continue; e.Row.AcceptChanges(); } }
/// <summary> /// Pre-Condition: The first column in the query is an AutoNumber field. /// Post-Condition: Child records will be persisted in the database /// consistent with the primary key of the parent record. /// Description: This method will synchronize the primary and foreign /// key together. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnRowUpdated(object sender, OleDbRowUpdatedEventArgs args) { int intNewID = 0; if (_dbConn.State == ConnectionState.Closed) { _dbConn.Open(); } OleDbCommand dbCmd = new OleDbCommand("SELECT @@IDENTITY", _dbConn); if (args.StatementType == StatementType.Insert) { intNewID = (int)dbCmd.ExecuteScalar(); args.Row[0] = intNewID; } }
/// <summary> /// the event handler that to automatic assign the current ID+1 to the new added row /// </summary> void DataAdapter_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { // When the update is an Insert (new record) if (e.StatementType == StatementType.Insert) { // Creates a new command // @@IDENTITY - a database function that returns the last-inserted identity (autonumber) value OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY", _connection); // Assigns the ID value of the new row in the database to the DataColumn "ID" of the new // DataRow in the DataTable // *** // ExecuteScalar - Executes the command and returns the value of first column of the first row // e.Row - reference to the DataRow added to the DataTable // e.Row["ID"] - reference to the "ID" DataColumn in the DataRow e.Row["ID"] = (int)cmd.ExecuteScalar(); } }
public static void SetPrimaryKey(OleDbTransaction trans, OleDbRowUpdatedEventArgs e) { if (e.Status == System.Data.UpdateStatus.Continue && e.StatementType == System.Data.StatementType.Insert) { // if this is an insert operation... var pk = e.Row.Table.PrimaryKey; // and primary key column exists... if (pk != null && pk.Length == 1) { var cmdGetIdentity = new OleDbCommand("SELECT @@IDENTITY", trans.Connection, trans); // Execute the post-update query to fetch the new @IDENTITY e.Row[pk[0]] = Convert.ToInt32(cmdGetIdentity.ExecuteScalar()); e.Row.AcceptChanges(); } } }
//////////////////////////////////////////////////// private void OnRowAIdAutoUpdated(object sender, OleDbRowUpdatedEventArgs e) { string strNomTableInDb = m_strNomTableInDb; string strId = e.Row.Table.PrimaryKey[0].ColumnName; string strRequete = "select max([" + strId + "]) from [" + strNomTableInDb + "]"; CResultAErreur result = m_connexion.ExecuteScalar(strRequete); if (!result) { throw new Exception(I.T("Access97 Recovery IdAuto Error|101")); } e.Row[strId] = (int)result.Data; if (m_bAvecSynchro && e.Row.Table.Columns.Contains(CSc2iDataConst.c_champIdSynchro)) { ((CAccess97DataBaseConnexionSynchronisable)m_connexion).RenseignerPourSynchro(e.Row, e.StatementType); } }
private void Adapter_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { if (e.StatementType == StatementType.Insert) { var cmd = new OleDbCommand("SELECT @@IDENTITY", e.Command.Connection); var oldId = e.Row["ID"]; var newId = cmd.ExecuteScalar(); e.Row["ID"] = newId; e.Row.AcceptChanges(); foreach (DataRow rs in _Blagajna_CvitanDataSet.StavkaRacun.Rows) { if (rs["idRacun"].Equals(oldId)) { rs["idRacun"] = newId; } } } }
protected void OnRowUpdated(object sender, OleDbRowUpdatedEventArgs e) { try { if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) { TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr(); OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY"); txMgr.Enlist(cmd, this); object o = cmd.ExecuteScalar(); txMgr.DeEnlist(cmd, this); if (o != null) { e.Row[this.GetAutoKeyColumn()] = o; e.Row.AcceptChanges(); } } } catch {} }
private void oleDBda_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { Exception exp = null; switch (e.StatementType) { case StatementType.Insert: try { BeginCase("RowInsert"); Compare(drInsert, e.Row); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } EventCounter++; break; case StatementType.Delete: try { BeginCase("RowDelete"); Compare(drDelete, e.Row); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } EventCounter++; break; case StatementType.Update: try { BeginCase("RowUpdate"); Compare(drUpdate, e.Row); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } EventCounter++; break; } }
/// <devdoc> /// Listens for the RowUpdate event on a dataadapter to support UpdateBehavior.Continue /// </devdoc> private void OnRowUpdated(object sender, OleDbRowUpdatedEventArgs e) { DataColumn _autoKeyField = null; if (e.RecordsAffected == 0) { if (e.Errors != null) { //e.Row.RowError = SR.ExceptionMessageUpdateDataSetRowFailure; e.Row.RowError = string.Format("{0}", e.Errors.Message); e.Status = UpdateStatus.SkipCurrentRow; } } foreach (DataColumn col in e.Row.Table.Columns) { if (col.AutoIncrement) { _autoKeyField = col; break; } } // Include a variable and a command to retrieve the identity value from the Access database. // NOTE: This technique only works with Access 2000 or higher if (_autoKeyField != null) { if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) { int newID = 0; OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", e.Command.Connection, e.Command.Transaction); // Retrieve the identity value and store it in the CategoryID column. newID = (int)idCMD.ExecuteScalar(); e.Row[_autoKeyField.ColumnName] = newID; } } }