我希望返回@from和@to之间的数据。 DB中的日期是nvarchar(max)类型。 Sql很好,因为当我设置@from和@to并在sql server中运行sql代码时,返回正确的结果。 XML不为空,有列名,但不是列数据。
public static DataSet Report(string from, string to)
{
DataSet ds = new DataSet("Rez");
using (SqlConnection conn = new SqlConnection(conf.ConnStrVienaSas))
{
using (SqlCommand cmd = new SqlCommand(FileReaderHelper.ReadSQLText("ExternalReports.sql"), conn))
{
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 180;
cmd.Parameters.Add("@from", SqlDbType.NVarChar).Value = from;
cmd.Parameters.Add("@to", SqlDbType.NVarChar).Value = to;
using (SqlDataAdapter adap = new SqlDataAdapter(cmd))
try
{
adap.Fill(ds);
}
catch (Exception ex)
{
ds = WSErrorExtenderHelper.CreateErrorDS(ex.ToString() /*"Error reading data from DB."*/);
}
}
}
return ds;
}
SQL片段:
SELECT [A].[FieldValue] AS Created_at, [B].[Created_by], [C].[Code1],
[D].[Code2], [E].[Code3], [F].[Code4]
FROM [dbo].[TEMP] A with (nolock)
INNER JOIN [dbo].[TEMP2] B with (nolock)
ON [A].[UserDefinedRowId] = [B].[UserDefinedRowId]
INNER JOIN [dbo].[TEMP3] C with (nolock)
ON [A].[UserDefinedRowId] = [C].[UserDefinedRowId]
INNER JOIN [dbo].[TEMP4] D with (nolock)
ON [A].[UserDefinedRowId] = [D].[UserDefinedRowId]
INNER JOIN [dbo].[TEMP5] E with (nolock)
ON [A].[UserDefinedRowId] = [E].[UserDefinedRowId]
INNER JOIN [dbo].[TEMP6] F with (nolock)
ON [A].[UserDefinedRowId] = [F].[UserDefinedRowId]
WHERE ([A].[FieldValue] between @from and @to)
答案 0 :(得分:1)
我相信使用:
conn.Open();
将解决您的问题