我正在开发一个应用程序,我必须从数据库中检索一些数据。我正在使用以下查询。
SELECT DISTINCT Context.ContextId, ContextName
FROM Context
INNER JOIN RunInstance
ON Context.ContextId IN
(SELECT RunInstance.ContextId
FROM RunInstance
INNER JOIN ProcessInstance
ON RunInstance.RunInstanceId
IN (SELECT RunInstanceId FROM ProcessInstance
WHERE RiskDate = '2010-08-20' ));
此查询在 SQL Server 2008 中完美运行。
但是,当我将它放在我的 C# 应用程序中时,它没有显示任何输出。
我的代码:
string squery = @"SELECT DISTINCT Context.ContextId, ContextName FROM Context INNER JOIN RunInstance ON Context.ContextId IN
(Select RunInstance.ContextId From RunInstance
INNER JOIN ProcessInstance ON RunInstance.RunInstanceId
IN (SELECT RunInstanceId FROM ProcessInstance Where
RiskDate = '2010-08-20' )); ";
using(SqlConnection sqcon = new SqlConnection("Data Source=WMLON-Z8-SQL20,61433;Initial Catalog=statusdb;Integrated Security=True")){
sqcon.Open();
using(SqlCommand command = new SqlCommand(squery,sqcon))
using(SqlDataReader reader = command.ExecuteReader()){
while(reader.Read()){
Console.WriteLine(reader[0]+"\t"+reader[1]);
}
}
}
谁能告诉我问题是什么?