[英]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.