我在.net中有一个奇怪的gridview问题,到目前为止我还没有找到问题所在。
我有一个由sqldatareader使用的存储过程。
问题正在发生。当我为参数输入一些特定值时,屏幕上的一切都会显示得很好。例如,我有日期和最小/最大数量,gridview被正确填充。
当我再包含一个参数时,比如说customer email,读者说它有行,但是gridview保持空白:
SqlDataReader rdrAdvancedReport = commAdvanced.ExecuteReader();
while (rdrAdvancedReport.Read())
{
gvResults.DataSource = rdrAdvancedReport;
gvResults.DataBind();
}
rdrAdvancedReport.Close();
更“有趣”的是,一旦gridview循环完成,我就有另一个循环,给我所有订单的总金额,并且标签填充正确。
if (rdrTotal.HasRows)
{
while (rdrTotal.Read())
{
orderTotalSum = orderTotalSum + Convert.ToDouble(rdrTotal["OrderTotal"]);
有什么问题吗?
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE SearchCust
(
@StartTime datetime = null,
@EndTime datetime = null,
@CustomerEmail nvarchar(255) = null,
@Username nvarchar(255) = null,
@CustomerName nvarchar(255) = null,
@MinimumOrderAmount decimal = null,
@MaximumOrderAmount decimal = null,
)
AS
BEGIN
SET NOCOUNT ON
SELECT DISTINCT o.OrderID, o.OrderTotal, o.ShippingCountry, n.Name AS OrderStatus, p.Name AS PaymentStatus FROM Order o
JOIN OrderStatus n ON o.OrderStatusID = n.OrderStatusID
JOIN PaymentStatus p ON o.OrderStatusID = p.PaymentStatusID
JOIN Customer c ON o.CustomerID = c.CustomerID
JOIN OrderProduct op ON o.OrderID = op.OrderID
JOIN ProductValue pv ON op.ProductVariantID = pv.ProductVariantId
WHERE (o.CreatedOn > @StartTime OR @StartTime IS NULL)
AND (o.CreatedOn < @EndTime OR @EndTime IS NULL)
AND (o.ShippingEmail = @CustomerEmail OR @CustomerEmail IS NULL)
AND (c.Username = @Username OR @Username IS NULL)
AND (o.BillingFirstName + ' ' + o.BillingLastName = @CustomerName OR @CustomerName IS NULL)
AND (o.ShippingFirstName + ' ' + o.ShippingLastName = @CustomerName OR @CustomerName IS NULL)
AND (o.OrderTotal > @MinimumOrderAmount or @MinimumOrderAmount IS NULL)
AND (o.OrderTotal < @MaximumOrderAmount OR @MaximumOrderAmount IS NULL)
ORDER BY o.OrderID
END
提前谢谢