Creating new instance - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Creating new instance

j9070749j9070749 Posts: 7Member
Hi, I am very new to C#, and have an error on click of the save button. I have created a simple WPF application using Visual Studio, and have a SQL databased linked in. I have 3 buttons on the page, one to go to the next record, one to nacigate to the previous, and one to save.

CollectionViewSource tblOrdersViewSource = null;
PO2DataSet PO2DataSet = null;
PO2DataSetTableAdapters.TblOrdersTableAdapter pO2DataSetTblOrdersTableAdapter;

private void Window_Loaded(object sender, RoutedEventArgs e)

WPFPurchaseOrders.PO2DataSet pO2DataSet = ((WPFPurchaseOrders.PO2DataSet)(this.FindResource("pO2DataSet")));
// Load data into the table TblOrders. You can modify this code as needed.
pO2DataSetTblOrdersTableAdapter = new WPFPurchaseOrders.PO2DataSetTableAdapters.TblOrdersTableAdapter();
tblOrdersViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("tblOrdersViewSource")));
// Load data into the table TblItem. You can modify this code as needed.
WPFPurchaseOrders.PO2DataSetTableAdapters.TblItemTableAdapter pO2DataSetTblItemTableAdapter = new WPFPurchaseOrders.PO2DataSetTableAdapters.TblItemTableAdapter();
System.Windows.Data.CollectionViewSource tblOrdersTblItemViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("tblOrdersTblItemViewSource")));

private void previousButton_Click(object sender, RoutedEventArgs e)

private void nextButton_Click(object sender, RoutedEventArgs e)

private void saveButton_Click(object sender, RoutedEventArgs e)
if (pO2DataSetTblOrdersTableAdapter.Update PO2DataSet.TblOrders) > 0)
MessageBox.Show("Changes were saved");
MessageBox.Show("No changes were made or saved");

The error is on the first line of the if statement. The error message 'NullReferenceException was unhandled'. When reading the troubleshooting tips it mentions creating a instance for the class, but I thought this was already done at the top of the code?

Any suggestions/explinations is much appriciated.

Many thanks.
Sign In or Register to comment.