代码如下:
[color=#00FFFF]paramSearch[4].Value = "(Account = '" + orderInfo.Account + "' AND ShopID = '" + orderInfo.ShopID + "' AND [Date] = '"+orderInfo.Date+"')";
paramSearch[5].Value = "OrderID";
paramSearch[6].Value = true;
paramSearch[7].Value = "OrderID";
int newOrderID=0;
SqlDataReader res = SQLHelper.ExecuteReader(SQLHelper.ConnectionString, CommandType.StoredProcedure, "Search", paramSearch);
if (res.Read())
{
newOrderID=Convert.ToInt32(res["OrderID"]);
}
res.Close();
return newOrderID;[/color]
其中 [Date] 为 ms sql server Datetime 类型 , orderInfo.Date是C# datetime 类型,
如表里 Date=2009-6-28 13:13:13 ; 就以orderInfo.Date = 2009-6-28 13:13:13为条件
但为什么就查不出数据,我敢肯定错在 [Date] = '"+orderInfo.Date+" 这个地方,在 vs 2005 直接查询时也查不出数据。去掉这个条件时可以查询出条件 。不知道什么原因啊!各位请多多指教我这个菜鸟啊!
[color=#00FFFF]paramSearch[4].Value = "(Account = '" + orderInfo.Account + "' AND ShopID = '" + orderInfo.ShopID + "' AND [Date] = '"+orderInfo.Date+"')";
paramSearch[5].Value = "OrderID";
paramSearch[6].Value = true;
paramSearch[7].Value = "OrderID";
int newOrderID=0;
SqlDataReader res = SQLHelper.ExecuteReader(SQLHelper.ConnectionString, CommandType.StoredProcedure, "Search", paramSearch);
if (res.Read())
{
newOrderID=Convert.ToInt32(res["OrderID"]);
}
res.Close();
return newOrderID;[/color]
其中 [Date] 为 ms sql server Datetime 类型 , orderInfo.Date是C# datetime 类型,
如表里 Date=2009-6-28 13:13:13 ; 就以orderInfo.Date = 2009-6-28 13:13:13为条件
但为什么就查不出数据,我敢肯定错在 [Date] = '"+orderInfo.Date+" 这个地方,在 vs 2005 直接查询时也查不出数据。去掉这个条件时可以查询出条件 。不知道什么原因啊!各位请多多指教我这个菜鸟啊!
数据库中DATETIME类型SELECT GETDATE()
------------------------------------------------------
2009-06-28 20:11:27.363(所影响的行数为 1 行)
DateTime d = DateTime.Now;
Console.Write(d);
他们的格式不同的,
CONVERT(VARCHAR(20),[Date],120)='"+orderInfo.Date+" ';
我想精确到时分秒,这样应该可以吧
convert(varchar(20),[Date],120) = '"+orderInfo.Date.ToString("yyyy-MM-dd hh:mm:ss")+"')";