} //end of Retrieve() #endregion #region IWriteDB Members /// <summary> /// </summary> public IBaseProps Create(IBaseProps p) { //return p; int rowsAffected = 0; CustomerProps props = (CustomerProps)p; DBCommand command = new DBCommand(); command.CommandText = "usp_CustomerCreate"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@CustomerID", SqlDbType.Int); command.Parameters.Add("@Name", SqlDbType.VarChar); command.Parameters.Add("@Address", SqlDbType.VarChar); command.Parameters.Add("@City", SqlDbType.VarChar); command.Parameters.Add("@State", SqlDbType.Char); command.Parameters.Add("@ZipCode", SqlDbType.Char); command.Parameters[0].Direction = ParameterDirection.Output; //Should not add value for productID because of autonumber, right? command.Parameters["@Name"].Value = props.name; command.Parameters["@Address"].Value = props.address; command.Parameters["@City"].Value = props.city; command.Parameters["@State"].Value = props.state; command.Parameters["@ZipCode"].Value = props.zipCode; try { rowsAffected = RunNonQueryProcedure(command); if (rowsAffected == 1) { props.id = (int)command.Parameters[0].Value; props.concurrencyID = 1; return(props); } else { throw new Exception("Unable to insert record. " + props.ToString()); } } catch (Exception e) { // log this error throw; } finally { if (mConnection.State == ConnectionState.Open) { mConnection.Close(); } } }
public IBaseProps Create(IBaseProps c) { int rowsAffected = 0; CustomerProps props = (CustomerProps)c; DBCommand command = new DBCommand(); command.CommandText = "usp_CustomerCreate"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@Name", SqlDbType.Int); command.Parameters.Add("@Address", SqlDbType.Char); command.Parameters.Add("@City", SqlDbType.VarChar); command.Parameters.Add("@State", SqlDbType.Money); command.Parameters.Add("@ZipCode", SqlDbType.Int); command.Parameters[0].Direction = ParameterDirection.Output; command.Parameters["@Name"].Value = props.Name; command.Parameters["@Address"].Value = props.Address; command.Parameters["@City"].Value = props.City; command.Parameters["@State"].Value = props.State; command.Parameters["@ZipCode"].Value = props.ZipCode; try { rowsAffected = RunNonQueryProcedure(command); //how many records were affected when I did this? if (rowsAffected == 1) { props.ID = (int)command.Parameters[0].Value; props.ConcurrencyID = 1; return(props); } else { throw new Exception("Unable to insert record. " + props.ToString()); } } catch (Exception e) { // log this error throw; } finally { if (mConnection.State == ConnectionState.Open) { mConnection.Close(); } } }
public IBaseProps Create(IBaseProps p) // possibly might need to change to props to match origional parameter. { // @CustomerID int output, //@Name varchar(100) // @Address varchar(50) // @City varchar(20) // @State char(2) // @ZipCode char(15) int rowsAffected = 0; CustomerProps props = (CustomerProps)p; DBCommand command = new DBCommand(); command.CommandText = "usp_CustomerCreate"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@CustomerID", SqlDbType.Int); command.Parameters.Add("@Name", SqlDbType.VarChar);// these match the parameters int he stored procedure. name adreess etc command.Parameters.Add("@Address", SqlDbType.VarChar); command.Parameters.Add("@City", SqlDbType.VarChar); command.Parameters.Add("@State", SqlDbType.Char); command.Parameters.Add("@ZipCode", SqlDbType.Char); command.Parameters[0].Direction = ParameterDirection.Output; // there were three statements here before, it did not include customerID ask about if it needs to be //added // assuming it would be redundant if it wasnt there before.... command.Parameters["@Name"].Value = props.name; command.Parameters["@Address"].Value = props.address; command.Parameters["@City"].Value = props.city; command.Parameters["@State"].Value = props.state; command.Parameters["@ZipCode"].Value = props.zipcode; try { rowsAffected = RunNonQueryProcedure(command); if (rowsAffected == 1) { props.ID = (int)command.Parameters[0].Value; props.ConcurrencyID = 1; return(props); } else { throw new Exception("Unable to insert record. " + props.ToString()); } } catch (Exception e) { // log this error throw; } finally { if (mConnection.State == ConnectionState.Open) { mConnection.Close(); } } }