0
我想返回@from和@to之間的數據。 DB中的日期是nvarchar(max)類型。 Sql很好,因爲當我設置@from和@to並在sql server中運行sql代碼時,返回正確的結果。 XML不爲空,有列名稱,但不包含列數據。SQL不返回數據
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)
是否以正確的格式的日期字符串? – drneel 2014-09-10 12:51:44
SQL的外觀如何?什麼是完整的異常堆棧跟蹤? – 2014-09-10 12:52:27
爲什麼你的日期字段是'nvarchar(max)'? – 2014-09-10 12:52:30