Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I am using this code for edit in wpf datagrid, but it getting error of null reference exception but data (SNo) is already filled in datagrid.

private void btnEdit_Click(object sender, RoutedEventArgs e)
{
InvoiceRecordsDataContext dataContext = new InvoiceRecordsDataContext();
InvoiceRecord irRow = dgInvoiceRecord.SelectedItem as InvoiceRecord;
int m = irRow.SNo;
"error its getting "Null Reference Exception"
InvoiceRecord ir = (from p in dataContext.InvoiceRecords
where p.SNo == irRow.SNo
select p).Single();
ir.ProjectDetail = irRow.ProjectDetail;
ir.InvoiceDetail = irRow.InvoiceDetail;
ir.MilestonePercentage = irRow.MilestonePercentage;
ir.Amount = irRow.Amount;
dataContext.SubmitChanges();
MessageBox.Show("Row Updated Successfully.");
DisplayInvoiceRecords();
}
Please help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted

1 solution

Either dgInvoiceRecord.SelectedItem is null, or dgInvoiceRecord.SelectedItem is not an instance of the InvoiceRecord class.

Debug your code to find out which is the case.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900