C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Creating new instance Posted by j9070749 on 10 Oct 2012 at 3:36 AM
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();
pO2DataSetTblOrdersTableAdapter.Fill(pO2DataSet.TblOrders);
tblOrdersViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("tblOrdersViewSource")));
tblOrdersViewSource.View.MoveCurrentToFirst();
// Load data into the table TblItem. You can modify this code as needed.
WPFPurchaseOrders.PO2DataSetTableAdapters.TblItemTableAdapter pO2DataSetTblItemTableAdapter = new WPFPurchaseOrders.PO2DataSetTableAdapters.TblItemTableAdapter();
pO2DataSetTblItemTableAdapter.Fill(pO2DataSet.TblItem);
System.Windows.Data.CollectionViewSource tblOrdersTblItemViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("tblOrdersTblItemViewSource")));
tblOrdersTblItemViewSource.View.MoveCurrentToFirst();
}

private void previousButton_Click(object sender, RoutedEventArgs e)
{
tblOrdersViewSource.View.MoveCurrentToPrevious();
}

private void nextButton_Click(object sender, RoutedEventArgs e)
{
tblOrdersViewSource.View.MoveCurrentToNext();
}

private void saveButton_Click(object sender, RoutedEventArgs e)
{
if (pO2DataSetTblOrdersTableAdapter.Update PO2DataSet.TblOrders) > 0)
{
MessageBox.Show("Changes were saved");
}
else
{
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.