Hello, I am getting the error object reference is not set to a instance
I am creating a new customer in the combobox select method but in the button click I go to update the customer but I get an error where I am updating the customer object. The error is here in this btn click:
this exact code error:
Customer newCreatedCustomer = new Customer(currentUser.UserID, TextboxFirstName.Text,
TextboxLastName.Text, TextboxAddress.Text, TextboxCity.Text,
ComboboxState.SelectedValue.ToString(), TextboxZip.Text, TextEmailAddress.Text);
UsersDB.UpdateCustomer(newCreatedCustomer);
private void BtnProfileEdit_Click(object sender, RoutedEventArgs e)
{
EnableControls();
if (boolBtnPush == true)
{
if (BtnProfileEdit.Content.Equals("Save"))
{
if(boolIsCustomer == true)
{
if (TextboxFirstName.Text.Equals(""))
{
MessageBox.Show("You 'MUST' enter a First name,", "WARNING", MessageBoxButton.OK);
}
else
{
try
{
Customer newCreatedCustomer = new Customer(currentUser.UserID, TextboxFirstName.Text,
TextboxLastName.Text, TextboxAddress.Text, TextboxCity.Text,
ComboboxState.SelectedValue.ToString(), TextboxZip.Text, TextEmailAddress.Text);
UsersDB.UpdateCustomer(newCreatedCustomer);
}
catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
}
}
else
{
MessageBox.Show("You must select 'Yes' in combobox Customer\n" +
"to add customer data.", "UnAcceptable", MessageBoxButton.OK);
}
}
}
boolBtnPush = true;
BtnProfileEdit.Content = "Save";
}
private void CboCustomer_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string cboValue = "";
if (CboCustomer.SelectedIndex > 0)
cboValue = ((ComboBoxItem)CboCustomer.SelectedItem).Content.ToString();
if(cboValue.Equals("Yes"))
{
boolIsCustomer = true;
User addCustomer = null;
Customer newCustomer = null;
MessageBoxResult result = MessageBox.Show("Updating database to customer status.",
"Customer Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
if (result == MessageBoxResult.Yes)
{
try
{
addCustomer = new User(currentUser.UserID, currentUser.Username,
currentUser.Password, currentUser.IsAdmin, currentUser.UserCreatedDate, boolIsCustomer);
UsersDB.UpdateCurrentUser(addCustomer);
newCustomer = new Customer(currentUser.UserID, currentUser.Username, null, null,
null, null, null, null);
UsersDB.CreateCustomer(newCustomer);
}
catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
}
}
}
What I have tried:
making new object different ways putting this code in other sections