示例#1
0
        private void SaveDataObject( SqlDataRow data )
        {
            // Setup command parameters
            data.SetParameters( command.Parameters );
            // Fill parameters with values from the object's properties
            data.FillParameters( command.Parameters );

            // Update or Insert depending on whether object exists on database
            if( data.IsSaved )
                ExecuteNonQuery( data.UpdateSQL );
            else
            {
                if( command.Parameters["@id"].Value == DBNull.Value )
                {
                    command.Parameters.Remove( command.Parameters["@id"] );
                    // Store the ID generated by the database.
                    data.Id = Convert.ToInt32( ExecuteScalar( data.InsertSQL + "; SELECT SCOPE_IDENTITY();" ) );
                }
                else
                {
                    // TODO: Do we need to turn off IDENTITY_INSERT if there's an exception?
                    // I'm thinking not because it resets between command queries.
                    ExecuteNonQuery( "SET IDENTITY_INSERT [{0}] ON; {1}; SET IDENTITY_INSERT [{0}] OFF;",
                        data.TableName, data.InsertWithIdSQL );
                }
            }

            // Flag object as having been saved to database
            data.SetSaved( true );
        }
示例#2
0
 private void FillDataObject( SqlDataRow data )
 {
 }