返回空引用异常

发布于 2024-10-19 03:49:13 字数 1383 浏览 0 评论 0原文

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请恋爱 2024-10-26 03:49:13

根据您的评论,看起来像这一行:

Health_Scheme_System.Scheme updscheme = Scheme.Find(x => x.SchemeID == SchemeID).FirstOrDefault();

没有返回任何内容。换句话说,不存在具有您正在使用的任何 ID 的方案。

您可以手动在数据库中检查 Scheme 并获取其 ID 值吗?然后,您可以通过将该值传递给SchemeID 参数来测试上述代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文