Returning a null Reference Exception
public void S开发者_高级运维chemeUpdate(int SchemeID, int InsurerID, string Name, string Description)
{
Health_Scheme_System.Scheme updscheme = Scheme.Find(x => x.SchemeID == SchemeID).FirstOrDefault();
//updscheme.SchemeID = SchemeID;
//updscheme.InsurerID = InsurerID;
updscheme.Name = Name;
updscheme.Description = Description;
updscheme.Save();
}
Calling the method
//Converting to integer and date
int SchemeID;
int.TryParse(txtSchemeID.Text, out SchemeID);
int insurerID;
int.TryParse(txtInsurerID.Text, out insurerID);
//Getting the parameters from the method
DataAccess updscheme = new DataAccess();
//DataAccess updrates = new DataAccess();
updscheme.SchemeUpdate(SchemeID, insurerID, txtName.Text, txtDescription.Text);
//updrates.RatesUpdate(SchemeID, txtRates.Text);
//Binding the gridView to display the updates
txtSchemeID.Visible = false;
txtInsurerID.Visible = false;
gvSchemeMain.DataSource = ds.GetRates();
gvSchemeMain.DataBind();
I think the problems is with the parameters..
Based on your comment it looks like this line:
Health_Scheme_System.Scheme updscheme = Scheme.Find(x => x.SchemeID == SchemeID).FirstOrDefault();
is not returning anything. In other words, there is no Scheme with an ID of whatever you're using.
Can you manually check in the database for a Scheme
and get it's ID value. You can then test the above code by passing that value into the SchemeID parameter.
精彩评论