简体   繁体   English

表适配器填充中未处理的System.NullReferenceException

[英]Unhandled System.NullReferenceException in Table Adapter Fill

I keep getting null value expression when the variable sDate does not exist in the data table. 当变量sDate在数据表中不存在时,我一直在获取空值表达式。 It works fine as long as there is a corresponding date in the table. 只要表中有相应的日期,它就可以正常工作。 dvtta is the Table Adapter. dvtta是表适配器。 Here is what I have so far: 这是我到目前为止的内容:

            object StartingBal = 0;
            StartingBal = (decimal)dvtta.Balance(acctno, sDate);
            if (StartingBal.GetType() != typeof(DBNull))
            {
                StartingBal = (decimal?)StartingBal;
                StartingBalance = Convert.ToDecimal(StartingBal);
            }
            else
            {
                StartingBalance = 0;
            }

I've been pulling my hair out on this. 我一直在为此扯头发。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Here is the code for Balance: 这是Balance的代码:

 SELECT SUM(AMOUNT) AS Expr1
 FROM     Trans
 WHERE  (ACCT = @account) AND (Date <= @baldate)

Have you tried 你有没有尝试过

if (StartingBal != null) { /* etc. */ }

If it isn't returning anything then aren't you setting your object StartingBal = null. 如果它不返回任何东西,那您就不会设置对象StartingBal = null。 In VB.NET this would be "StartingBal Is Nothing" which worked for me in a very similar situation. 在VB.NET中,这是“ StartingBal Nothing”,它在非常相似的情况下对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.NullReferenceException 未被用户代码处理 - System.NullReferenceException was unhandled by user code 连接到Com5:未处理System.NullReferenceException - Connecting to Com5: System.NullReferenceException was unhandled WindowsFormsApplication1.exe中发生了类型为&#39;System.NullReferenceException&#39;的未处理异常 - An unhandled exception of type 'System.NullReferenceException' occurred in WindowsFormsApplication1.exe C# Bunifu UI System.NullReferenceException 未处理 - C# Bunifu UI System.NullReferenceException was unhandled .NET WinForms应用程序在退出时由于未处理的System.NullReferenceException崩溃 - .NET WinForms app crashing on exit with unhandled System.NullReferenceException C#错误? -用户代码未处理System.NullReferenceException - C# Bug? - System.NullReferenceException was unhandled by user code 单击TreeNode时发生未处理的“System.NullReferenceException”类型的异常 - An unhandled exception of type 'System.NullReferenceException' occurring when clicking TreeNode 用户代码未处理ASP MVC,System.NullReferenceException - ASP MVC, System.NullReferenceException was unhandled by user code 错误System.NullReferenceException - Error System.NullReferenceException LINQ中的System.NullReferenceException - System.NullReferenceException in LINQ
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM