-6

注文表から最近の「注文」を表示しようとしています。しかし、テーブルにいくつかの注文がある場合でも、「取得する注文はありません」というメッセージが表示されます。コードの何が問題になっていますか?

public static List<OrderInfo> GetOrdersByRecent (int count)
{
    DbCommand comm = GenericDataAccess.CreateCommand ();
    comm.CommandText = "OrdersGetByRecent";
    DbParameter param = comm.CreateParameter ();
    param.ParameterName = "@Count";
    param.Value = count;
    param.DbType = DbType.Int32;
    comm.Parameters.Add (param);
    return ConvertDataTableToOrders (GenericDataAccess.ExecuteSelectCommand (comm));
}

protected void byRecentGo_Click(object sender, EventArgs e)
{
    try
    {
        int recordCount = Int32.Parse(recentCountTextBox.Text);
        List<OrderInfo> orders = CommerceLibAccess.GetOrdersByRecent(recordCount);
        grid.DataSource = orders;
        if (orders.Count == 0)
        {
            errorLabel.Text = "<br />No orders to get.";
        }
    }
    catch
    {
        errorLabel.Text = "<br />Couldn't get the requested orders!";
    }
    finally
    {
        grid.DataBind();
    }
}
4

2 に答える 2

1

あなたはゼロ注文を得ます

List<OrderInfo> orders = CommerceLibAccess.GetOrdersByRecent(recordCount);

空のリストを返しています。


次の理由により、空のリストが返されます。

return ConvertDataTableToOrders (GenericDataAccess.ExecuteSelectCommand (comm));

空のデータテーブルを返しています。

データ テーブルが空であると考える理由を理解するには、データ テーブルを掘り下げる必要があります。
(実際は空だからでしょうか??)

于 2013-08-23T17:15:28.070 に答える
-1

テーブル フィールド「OrderID」と OrderID の OrderInfo 属性は同じである必要があります

class OrderInfo
{

int OrderID;

}

これをチェックして...

于 2013-08-23T17:14:09.330 に答える