public Customer AddCustomerToDB(Customer newCustomer) {
Customer customerToReturn;
SqlCommand cmd = GetDbCommand();
//Setup our SELECT statement (sql)
cmd.CommandText = @"
INSERT INTO [AdventureWorksLT2012].[SalesLT].[Customer]
(NameStyle, Title, FirstName, MiddleName, LastName, Suffix, CompanyName, SalesPerson,
EmailAddress, Phone, PasswordHash, PasswordSalt)
VALUES
(@NameStyle, @Title, @FirstName, @MiddleName, @LastName, @Suffix, @CompanyName, @SalesPerson,
@EmailAddress, @Phone, @PasswordHash, @PasswordSalt);
SELECT @@Identity from [AdventureWorksLT2012].[SalesLT].[Customer]
";
cmd.Parameters.AddWithValue("@NameStyle", newCustomer.NameStyle);
cmd.Parameters.AddWithValue("@Title", newCustomer.Title);
cmd.Parameters.AddWithValue("@FirstName", newCustomer.FirstName);
cmd.Parameters.AddWithValue("@MiddleName", newCustomer.MiddleName);
cmd.Parameters.AddWithValue("@LastName", newCustomer.LastName);
cmd.Parameters.AddWithValue("@Suffix", newCustomer.Suffix);
cmd.Parameters.AddWithValue("@CompanyName", newCustomer.CompanyName);
cmd.Parameters.AddWithValue("@SalesPerson", newCustomer.SalesPerson);
cmd.Parameters.AddWithValue("@EmailAddress", newCustomer.EmailAddress);
cmd.Parameters.AddWithValue("@Phone", newCustomer.Phone);
cmd.Parameters.AddWithValue("@PasswordHash", newCustomer.PasswordHash);
cmd.Parameters.AddWithValue("@PasswordSalt", newCustomer.PasswordSalt);
//cmd.Parameters.AddWithValue("@RowGuid", newCustomer.RowGuid);
object objNewCustomerId;
try
{
cmd.Connection.Open();
objNewCustomerId= cmd.ExecuteScalar();
cmd.Connection.Close();
}
catch (Exception ex)
{
throw;
}
customerToReturn = GetCustomer((int)objNewCustomerId);
return customerToReturn;
}