Esempio n. 1
0
 /// <devdoc>
 /// Listens for the RowUpdate event on a dataadapter to support UpdateBehavior.Continue
 /// </devdoc>
 private void OnSqlRowUpdated(object sender, SqlCeRowUpdatedEventArgs rowThatCouldNotBeWritten)
 {
     if (rowThatCouldNotBeWritten.RecordsAffected == 0)
     {
         if (rowThatCouldNotBeWritten.Errors != null)
         {
             rowThatCouldNotBeWritten.Row.RowError = Resources.ExceptionMessageUpdateDataSetRowFailure;
             rowThatCouldNotBeWritten.Status       = UpdateStatus.SkipCurrentRow;
         }
     }
 }
Esempio n. 2
0
        private void OnRowUpdated(object sender, SqlCeRowUpdatedEventArgs args)
        {
            DbDataAdapter da = (DbDataAdapter)sender;

            if (!updateHandlers.ContainsKey(da))
            {
                throw new NDOException(314, "OnRowUpdated event can't be scheduled to a DataAdapter.");
            }
            IRowUpdateListener handler = updateHandlers[da];

            handler.OnRowUpdate(args.Row);
        }
 private void appointmentsTableAdapter_RowUpdated(object sender, SqlCeRowUpdatedEventArgs e)
 {
     // Gets ID for a new appointment from the SQL CE data source
     if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
     {
         int id = 0;
         using (SqlCeCommand cmd = new SqlCeCommand("SELECT @@IDENTITY",
                                                    appointmentsTableAdapter.Connection)) {
             id = Convert.ToInt32(cmd.ExecuteScalar());
         }
         e.Row["UniqueID"] = id;
     }
 }
Esempio n. 4
0
 void _adapter_RowUpdated(object sender, SqlCeRowUpdatedEventArgs e)
 {
     if (e.Status == UpdateStatus.Continue &&
         e.StatementType == StatementType.Insert)
     {
         var pk = e.Row.Table.PrimaryKey;
         pk[0].ReadOnly = false;
         SqlCeCommand cmd = new SqlCeCommand("SELECT @@IDENTITY",
                                             e.Command.Connection, e.Command.Transaction);
         object id = (decimal)cmd.ExecuteScalar();
         e.Row[pk[0]] = Convert.ToInt32(id);
         e.Row.AcceptChanges();
     }
 }
Esempio n. 5
0
        public static void SetPrimaryKey(SqlCeTransaction trans, SqlCeRowUpdatedEventArgs e)
        {
            // If this is an INSERT operation...
            if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
            {
                System.Data.DataColumn[] pk = e.Row.Table.PrimaryKey;
                // and a primary key PK column exists...
                if (pk != null && pk.Length == 1)
                {
                    //Set up the post-update query to fetch new @@Identity
                    SqlCeCommand cmdGetIdentity = new SqlCeCommand("SELECT @@IDENTITY", (SqlCeConnection)trans.Connection, trans);

                    //Execute the command and set the result identity value to the PK
                    e.Row[pk[0]] = Convert.ToInt32(cmdGetIdentity.ExecuteScalar());
                    e.Row.AcceptChanges();
                }
            }
        }
Esempio n. 6
0
 void RowUpdated(Object sender, SqlCeRowUpdatedEventArgs e)
 {
     if (e.Errors == null)
     {
         if (e.StatementType == StatementType.Insert)
         {
             try
             {
                 e.Command.CommandText = "SELECT @@IDENTITY;";
                 e.Row[0] = e.Command.ExecuteScalar();
                 e.Command.Transaction.Commit();
                 e.Row.AcceptChanges();
             }
             catch
             { e.Command.Transaction.Rollback(); }
         }
     }
     else
     {
         e.Command.Transaction.Rollback();
         MessageBox.Show(e.Errors.ToString());
     }
     e.Command.Transaction = null;
 }
        protected static void OnRowUpdated(object sender, SqlCeRowUpdatedEventArgs e)
        {
            try
            {
                PropertyCollection props = e.Row.Table.ExtendedProperties;
                if (props.ContainsKey("props"))
                {
                    props = (PropertyCollection)props["props"];
                }

                if (e.Status == UpdateStatus.Continue && (e.StatementType == StatementType.Insert || e.StatementType == StatementType.Update))
                {
                    esDataRequest request = props["esDataRequest"] as esDataRequest;
                    esEntitySavePacket packet = (esEntitySavePacket)props["esEntityData"];

                    if (e.StatementType == StatementType.Insert)
                    {
                        if (props.Contains("AutoInc"))
                        {
                            string autoInc = props["AutoInc"] as string;

                            SqlCeCommand cmd = new SqlCeCommand();
                            cmd.Connection = e.Command.Connection;
                            cmd.Transaction = e.Command.Transaction;

                            cmd.CommandText = "SELECT @@IDENTITY";
                            cmd.CommandType = CommandType.Text;

                            object o = null;

                            #region Profiling
                            if (sTraceHandler != null)
                            {
                                using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "OnRowUpdated", System.Environment.StackTrace))
                                {
                                    try
                                    {
                                        o = cmd.ExecuteScalar();
                                    }
                                    catch (Exception ex)
                                    {
                                        esTrace.Exception = ex.Message;
                                        throw;
                                    }
                                }
                            }
                            else
                            #endregion
                            {
                                o = cmd.ExecuteScalar();
                            }

                            if (o != null)
                            {
                                packet.CurrentValues[autoInc] = o;
                                e.Row[autoInc] = o;
                            }
                        }

                        if (props.Contains("EntitySpacesConcurrency"))
                        {
                            string esConcurrencyColumn = props["EntitySpacesConcurrency"] as string;
                            packet.CurrentValues[esConcurrencyColumn] = 1;
                        }
                    }

                    //-------------------------------------------------------------------------------------------------
                    // Fetch any defaults, SQLite doesn't support output parameters so we gotta do this the hard way
                    //-------------------------------------------------------------------------------------------------
                    if (props.Contains("Defaults"))
                    {
                        // Build the Where parameter and parameters
                        SqlCeCommand cmd = new SqlCeCommand();
                        cmd.Connection = e.Command.Connection;
                        cmd.Transaction = e.Command.Transaction;

                        string select = (string)props["Defaults"];

                        string[] whereParameters = ((string)props["Where"]).Split(',');

                        string comma = String.Empty;
                        string where = String.Empty;
                        int i = 1;
                        foreach (string parameter in whereParameters)
                        {
                            SqlCeParameter p = new SqlCeParameter("@p" + i++.ToString(), e.Row[parameter]);
                            cmd.Parameters.Add(p);
                            where += comma + "[" + parameter + "]=" + p.ParameterName;
                            comma = " AND ";
                        }

                        // Okay, now we can execute the sql and get any values that have defaults that were
                        // null at the time of the insert and/or our timestamp
                        cmd.CommandText = "SELECT " + select + " FROM [" + request.ProviderMetadata.Source + "] WHERE " + where + ";";

                        SqlCeDataReader rdr = null;

                        try
                        {
                            #region Profiling
                            if (sTraceHandler != null)
                            {
                                using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "OnRowUpdated", System.Environment.StackTrace))
                                {
                                    try
                                    {
                                        rdr = cmd.ExecuteReader(CommandBehavior.SingleResult);
                                    }
                                    catch (Exception ex)
                                    {
                                        esTrace.Exception = ex.Message;
                                        throw;
                                    }
                                }
                            }
                            else
                            #endregion
                            {
                                rdr = cmd.ExecuteReader(CommandBehavior.SingleResult);
                            }

                            if (rdr.Read())
                            {
                                select = select.Replace("[", String.Empty).Replace("]", String.Empty);
                                string[] selectCols = select.Split(',');

                                for (int k = 0; k < selectCols.Length; k++)
                                {
                                    packet.CurrentValues[selectCols[k]] = rdr.GetValue(k);
                                }
                            }
                        }
                        finally
                        {
                            // Make sure we close the reader no matter what
                            if (rdr != null) rdr.Close();
                        }
                    }

                    if (e.StatementType == StatementType.Update)
                    {
                        string colName = props["EntitySpacesConcurrency"] as string;
                        object o = e.Row[colName];

                        switch (Type.GetTypeCode(o.GetType()))
                        {
                            case TypeCode.Int16: packet.CurrentValues[colName] = ((System.Int16)o) + 1; break;
                            case TypeCode.Int32: packet.CurrentValues[colName] = ((System.Int32)o) + 1; break;
                            case TypeCode.Int64: packet.CurrentValues[colName] = ((System.Int64)o) + 1; break;
                            case TypeCode.UInt16: packet.CurrentValues[colName] = ((System.UInt16)o) + 1; break;
                            case TypeCode.UInt32: packet.CurrentValues[colName] = ((System.UInt32)o) + 1; break;
                            case TypeCode.UInt64: packet.CurrentValues[colName] = ((System.UInt64)o) + 1; break;
                        }
                    }
                }
            }
            catch { }
        }
Esempio n. 8
0
		/// <devdoc>
		/// Listens for the RowUpdate event on a dataadapter to support UpdateBehavior.Continue
		/// </devdoc>
		private void OnSqlRowUpdated(object sender, SqlCeRowUpdatedEventArgs rowThatCouldNotBeWritten)
		{
			if (rowThatCouldNotBeWritten.RecordsAffected == 0)
			{
				if (rowThatCouldNotBeWritten.Errors != null)
				{
					rowThatCouldNotBeWritten.Row.RowError = Resources.ExceptionMessageUpdateDataSetRowFailure;
					rowThatCouldNotBeWritten.Status = UpdateStatus.SkipCurrentRow;
				}
			}
		}
Esempio n. 9
0
 private void _adapter_RowUpdated(object sender, SqlCeRowUpdatedEventArgs e)
 {
     SQLCEIDHelper.SetPrimaryKey(this.Transaction, e);
 }
        protected static void OnRowUpdated(object sender, SqlCeRowUpdatedEventArgs e)
        {
            try
            {
                PropertyCollection props = e.Row.Table.ExtendedProperties;
                if (props.ContainsKey("props"))
                {
                    props = (PropertyCollection)props["props"];
                }

                if (e.Status == UpdateStatus.Continue && (e.StatementType == StatementType.Insert || e.StatementType == StatementType.Update))
                {
                    esDataRequest      request = props["esDataRequest"] as esDataRequest;
                    esEntitySavePacket packet  = (esEntitySavePacket)props["esEntityData"];

                    if (e.StatementType == StatementType.Insert)
                    {
                        if (props.Contains("AutoInc"))
                        {
                            string autoInc = props["AutoInc"] as string;

                            SqlCeCommand cmd = new SqlCeCommand();
                            cmd.Connection  = e.Command.Connection;
                            cmd.Transaction = e.Command.Transaction;

                            cmd.CommandText = "SELECT @@IDENTITY";
                            cmd.CommandType = CommandType.Text;

                            object o = null;
                            o = cmd.ExecuteScalar();

                            if (o != null)
                            {
                                packet.CurrentValues[autoInc] = o;
                                e.Row[autoInc] = o;
                            }
                        }

                        if (props.Contains("EntitySpacesConcurrency"))
                        {
                            string esConcurrencyColumn = props["EntitySpacesConcurrency"] as string;
                            packet.CurrentValues[esConcurrencyColumn] = 1;
                        }
                    }

                    //-------------------------------------------------------------------------------------------------
                    // Fetch any defaults, SQLite doesn't support output parameters so we gotta do this the hard way
                    //-------------------------------------------------------------------------------------------------
                    if (props.Contains("Defaults"))
                    {
                        // Build the Where parameter and parameters
                        SqlCeCommand cmd = new SqlCeCommand();
                        cmd.Connection  = e.Command.Connection;
                        cmd.Transaction = e.Command.Transaction;

                        string select = (string)props["Defaults"];

                        string[] whereParameters = ((string)props["Where"]).Split(',');

                        string comma = String.Empty;
                        string where = String.Empty;
                        int i = 1;
                        foreach (string parameter in whereParameters)
                        {
                            SqlCeParameter p = new SqlCeParameter("@p" + i++.ToString(), e.Row[parameter]);
                            cmd.Parameters.Add(p);
                            where += comma + "[" + parameter + "]=" + p.ParameterName;
                            comma  = " AND ";
                        }

                        // Okay, now we can execute the sql and get any values that have defaults that were
                        // null at the time of the insert and/or our timestamp
                        cmd.CommandText = "SELECT " + select + " FROM [" + request.ProviderMetadata.Source + "] WHERE " + where + ";";

                        SqlCeDataReader rdr = null;

                        try
                        {
                            rdr = cmd.ExecuteReader(CommandBehavior.SingleResult);

                            if (rdr.Read())
                            {
                                select = select.Replace("[", String.Empty).Replace("]", String.Empty);
                                string[] selectCols = select.Split(',');

                                for (int k = 0; k < selectCols.Length; k++)
                                {
                                    packet.CurrentValues[selectCols[k]] = rdr.GetValue(k);
                                }
                            }
                        }
                        finally
                        {
                            // Make sure we close the reader no matter what
                            if (rdr != null)
                            {
                                rdr.Close();
                            }
                        }
                    }

                    if (e.StatementType == StatementType.Update)
                    {
                        string colName = props["EntitySpacesConcurrency"] as string;
                        object o       = e.Row[colName];

                        switch (Type.GetTypeCode(o.GetType()))
                        {
                        case TypeCode.Int16: packet.CurrentValues[colName] = ((System.Int16)o) + 1; break;

                        case TypeCode.Int32: packet.CurrentValues[colName] = ((System.Int32)o) + 1; break;

                        case TypeCode.Int64: packet.CurrentValues[colName] = ((System.Int64)o) + 1; break;

                        case TypeCode.UInt16: packet.CurrentValues[colName] = ((System.UInt16)o) + 1; break;

                        case TypeCode.UInt32: packet.CurrentValues[colName] = ((System.UInt32)o) + 1; break;

                        case TypeCode.UInt64: packet.CurrentValues[colName] = ((System.UInt64)o) + 1; break;
                        }
                    }
                }
            }
            catch { }
        }