我从SQL存储过程返回2个结果 -
Select SUM(abcd) from rstuv
Select SUM(lmnop) from zxy
然后在我的C#中,我将这些分配给Data Tables
,就像这样
DataTable firstreturnedresult = ds.Tables[0];
DataTable secondreturnedresult = ds.Tables[1];
问题是如何为SUM()
中包含的Data Set
分配十进制变量?
答案 0 :(得分:2)
显示的查询使用标量函数SUM,因此结果是一个数据表,由一行和一列组成。要获得该值并将其分配给十进制变量,您可以写:
$ du -sh .
$ du -chs *
$ du -chs * | tail -1
仅当数据库表包含至少一行SUM时,此方法才能正常工作。如果数据库表为空,则返回表的第一列包含值DbNull.Value,您需要注意这一点并避免转换会触发异常
decimal sum1 = Convert.ToDecimal(firstreturnedresult.Rows[0][0]);
还要考虑更改如何检索您的值。您可以选择简单的SqlCommand和对ExecuteScalar的调用
,而不是构建SqlDataAdapter所需的所有基础结构。像这样的东西
decimal sum1 = 0;
if(firstreturnedresult.Rows[0][0] != DBNull.Value)
sum1 = Convert.ToDecimal(firstreturnedresult.Rows[0][0]);
答案 1 :(得分:1)
您可能正在对SQL命令使用UIViewControllerTransitioningDelegate
。在命令中使用方法。这将为您提供一个单一的价值。
import UIKit
class changeRootVCSeguePushUp: UIStoryboardSegue {
override func perform() {
let applicationDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let sourceView = self.sourceViewController.view
let destinationView = self.destinationViewController.view
let sourceFrame = sourceView.frame
let destinationStartFrame = CGRect(x: 0, y: sourceFrame.height, width: sourceFrame.width, height: sourceFrame.height)
let destinationEndFrame = CGRect(x: 0, y: 0, width: sourceFrame.width, height: sourceFrame.height)
destinationView.frame = destinationStartFrame
applicationDelegate.window?.insertSubview(self.destinationViewController.view, aboveSubview: self.sourceViewController.view )
UIView.animateWithDuration(0.25, animations: {
destinationView.frame = destinationEndFrame
}, completion: {(finished: Bool) -> Void in
self.sourceViewController.view.removeFromSuperview()
applicationDelegate.window?.rootViewController = self.destinationViewController
})
}
}