返回空引用异常
public void SchemeUpdate(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();
我认为问题出在参数上。
public void SchemeUpdate(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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的评论,看起来像这一行:
没有返回任何内容。换句话说,不存在具有您正在使用的任何 ID 的方案。
您可以手动在数据库中检查
Scheme
并获取其 ID 值吗?然后,您可以通过将该值传递给SchemeID 参数来测试上述代码。Based on your comment it looks like this line:
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.