读书人

求解关于使用参数传Where In语句的一

发布时间: 2013-01-18 10:22:42 作者: rapoo

求解,关于使用参数传Where In语句的一个错误
这是执行SQL语句的方法


public DataTable GetData(string sql, string ATableName, SqlParameter[] sqlparam)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
try
{
SqlCommand sqlComm = new SqlCommand(sql, GetConnection());
for (int j = 0; j < sqlparam.Length; j++)
{
sqlComm.Parameters.Add(sqlparam[j]);
}
using (SqlDataAdapter da = new SqlDataAdapter(sqlComm))
{
da.Fill(ds, ATableName);
}
dt = ds.Tables[0];
}
catch (Exception e)
{
throw e;
}
finally
{
ColseConnection();
}
return dt;
}

这是传的sql语句

if object_id(N'tempdb..#temp_6e8866c7d2ff438685f272ea0f5b8644',N'U') is not null drop table #temp_6e8866c7d2ff438685f272ea0f5b8644;
Select * into #temp_6e8866c7d2ff438685f272ea0f5b8644
from
(
Select DISTINCT a.[组织编号] as col, row_number()over(order by b.n desc)RowNo, ISNULL(b.n,0) as n
From [View_Statistics] a
LEFT join
(
Select DISTINCT [组织编号] as col, COUNT(*) as n
from [View_Statistics]
Where [报修时间] between @beginDate and @endDate and


[组织编号] in (@Param_0_0,@Param_0_1,@Param_0_2,@Param_0_3,@Param_0_4,@Param_0_5)
group by [组织编号]
) b
on a.[组织编号] = b.col
group by a.[组织编号],b.n) T;
declare @sumNum int;
Set @sumNum = (select SUM(n) from #temp_6e8866c7d2ff438685f272ea0f5b8644);
Select col,n,Convert(decimal(18,2),CAST(n*100 AS FLOAT)/@sumNum) as ratio,Convert(decimal(18,2),
CAST((select sum(n) from #temp_6e8866c7d2ff438685f272ea0f5b8644 where RowNo<=A.RowNo)*100 AS FLOAT) /@sumNum ) as total
From #temp_6e8866c7d2ff438685f272ea0f5b8644 A
Group by RowNo,col,n
Order by n desc;
if object_id(N'tempdb..#temp_6e8866c7d2ff438685f272ea0f5b8644',N'U') is not null drop table #temp_6e8866c7d2ff438685f272ea0f5b8644;


这是传的参数
求解,关于使用参数传Where In语句的一个异常

我把参数里的值取出来,放在数据库里面执行得到的结果为:
求解,关于使用参数传Where In语句的一个异常

然后我在程序里面执行的结果为:
求解,关于使用参数传Where In语句的一个异常

在数据库里面得到的是正确的结果,
为啥程序里确有问题呢?
我就郁闷了,我这是哪里错了呀?

[解决办法]
按道理 应该不会,估计还是代码中的sql和查询中的sql有出入,仔细查一下
[解决办法]
用SQL Server Profiler 查下具体发送的执行语句,执行下,看结果
[解决办法]
你的数据库不会连错了吧,debug c#中的sql拼接语句,把它弄到sql执行一下看看。

读书人网 >C#

热点推荐