C#SQL查询变量返回每一行 [英] c# sql query variable return for each row
本文介绍了C#SQL查询变量返回每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在查看2个日期列的表上运行2个查询:
//这给出了过去的天数
I want to run 2 queries on a table that look at 2 date columns:
// this gives the number of days gone
Select DATEDIFF (DAY, DeployedDate, ReturnedDate)
From Deployment
Where EmployeeID =1
And
DeploymentID = 1";
//这给出了他们离开多少天前
// this gives how many days ago they left
Select DATEDIFF (DAY, DeployedDate, GETDATE())
From Deployment
Where EmployeeID =1
And
DeploymentID = 1";
我想从我可以用C#代码处理的每一行中返回一个整数变量,然后解析下一行直到解析所有行.我无法让DataReader返回变量然后循环,而ExecuteScalar仅返回第一行.有任何想法吗?
I want to return an integer variable from each row that I can manipulate with c# code, then parse the next row until I parse all rows. I can''t get DataReader to return variables and then loop, and ExecuteScalar only returns the first row. Any ideas?
推荐答案
我认为SqlDataReader将有助于解决此问题.
谢谢
坎南
www.steadfastglobal.com
Hi,
I think SqlDataReader will help to solve this problem.
Thanks
Kannan
www.steadfastglobal.com
ExecuteScalar
将仅根据查询是否返回结果来返回值.
为什么不返回DataReader中的所有行,然后编写一些逻辑以将返回值转换为整数.
ExecuteScalar
will only return a value based on whether the query returned a result or not.
Why don''t you return all rows in a DataReader and then write some logic to convert the return value into an integer.
这篇关于C#SQL查询变量返回每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文