0

ジェネリックコレクションにデータを入力しようとしていますが、問題があります。リストを保存することになっているmyBookingsにデータを入力しようとしています。以下のメソッドはmyBookingsに正しいリストを入力する必要がありますが、何らかの理由で結果(int c)をカウントすると、0が返されます。誰かが私が間違っていることを確認できますか?

// .cs

public partial class _Default : System.Web.UI.Page
{    
    iClean.Bookings myBookings = new iClean.Bookings();
    iClean.Booking myBooking = new iClean.Booking();
    iClean.Controller myController = new iClean.Controller();

    ListItem li = new ListItem();

    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentFname.Text = Profile.FirstName;
        CurrentUname.Text = Profile.UserName;
        CurrentLname.Text = Profile.LastName;

        myBookings.AllBookings = this.GetBookings();

        int c = myBookings.AllBookings.Count();

        Name.Text = c.ToString();
        Address.Text = myBooking.Address;
        Phone.Text = myBooking.Phone;
        Date.Text = myBooking.DueDate.ToString();
        Comments.Text = myBooking.Comments;        
    }

    public List<iClean.Booking> GetBookings()
    {
        List<iClean.Booking> bookings = new List<iClean.Booking>();
        ArrayList records = this.Select("Bookings", "");
        for (int i = 0; i < records.Count; i++)
        {
            iClean.Booking tempBooking = new iClean.Booking();
            Hashtable row = (Hashtable)records[i];
            tempBooking.ID = Convert.ToInt32(row["ID"]);
            tempBooking.Name = Convert.ToString(row["ClientName"]);
            tempBooking.Address = Convert.ToString(row["ClientAddress"]);
            tempBooking.Phone = Convert.ToString(row["ClientPhone"]);

            tempBooking.DueDate = Convert.ToDateTime(row["Bookingdate"]);
            tempBooking.Completed = Convert.ToBoolean(row["Completed"]);
            tempBooking.Paid = Convert.ToBoolean(row["Paid"]);
            tempBooking.Cancelled = Convert.ToBoolean(row["Cancelled"]);
            tempBooking.ReasonCancelled = Convert.ToString(row["ReasonCancelled"]);
            tempBooking.ContractorPaid = Convert.ToBoolean(row["ContractorPaid"]);
            tempBooking.Comments = Convert.ToString(row["Comments"]);

            tempBooking.Windows = Convert.ToBoolean(row["Windows"]);
            tempBooking.Gardening = Convert.ToBoolean(row["Gardening"]);
            tempBooking.IndoorCleaning = Convert.ToBoolean(row["IndoorCleaning"]);

            bookings.Add(tempBooking);
        }

        return bookings;
    }

    public ArrayList Select(string table, string conditions)
    {
        // Create something to hosue the records.
        ArrayList records = new ArrayList();

        try
        {
            // Open a connection.
            OleDbConnection myConnection = new OleDbConnection(this.getConnectionString());
            myConnection.Open();

            // Generate the SQL
            string sql = "SELECT * FROM " + table;
            if (conditions != "") { sql += " WHERE " + conditions; }

            // Console.WriteLine("Select SQL: " + sql); // In case we need to debug

            // Run the SQL
            OleDbCommand myCommand = new OleDbCommand(sql, myConnection);
            OleDbDataReader myReader = myCommand.ExecuteReader();

            // Go through the rows that were returned ...
            while (myReader.Read())
            {
                // ... create Hashtable to keep the columns in, ...
                Hashtable row = new Hashtable();

                // ... add the fields ...
                for (int i = 0; i < myReader.FieldCount; i++)
                {
                    row.Add(myReader.GetName(i), myReader[i]);
                }

                // ... and store the row.
                records.Add(row);
            }

            // Make sure to close the connection
            myConnection.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }

        return records;
    }

    public string getConnectionString()
    {
        string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=IQQuotes.accdb;";

        return connectionString;
    }
}
4

1 に答える 1

0

推測ですが、これを試してください:

public List<iClean.Booking> GetBookings()
{
    List<iClean.Booking> bookings = new List<iClean.Booking>();
    ArrayList records = this.Select("Bookings", "");
    iClean.Booking tempBooking = new iClean.Booking();
    for (int i = 0; i < records.Count; i++)
    {
        tempBooking = new iClean.Booking();
        Hashtable row = (Hashtable)records[i];
        tempBooking.ID = Convert.ToInt32(row["ID"]);
        tempBooking.Name = Convert.ToString(row["ClientName"]);
        tempBooking.Address = Convert.ToString(row["ClientAddress"]);
        tempBooking.Phone = Convert.ToString(row["ClientPhone"]);

        tempBooking.DueDate = Convert.ToDateTime(row["Bookingdate"]);
        tempBooking.Completed = Convert.ToBoolean(row["Completed"]);
        tempBooking.Paid = Convert.ToBoolean(row["Paid"]);
        tempBooking.Cancelled = Convert.ToBoolean(row["Cancelled"]);
        tempBooking.ReasonCancelled = Convert.ToString(row["ReasonCancelled"]);
        tempBooking.ContractorPaid = Convert.ToBoolean(row["ContractorPaid"]);
        tempBooking.Comments = Convert.ToString(row["Comments"]);

        tempBooking.Windows = Convert.ToBoolean(row["Windows"]);
        tempBooking.Gardening = Convert.ToBoolean(row["Gardening"]);
        tempBooking.IndoorCleaning = Convert.ToBoolean(row["IndoorCleaning"]);

        bookings.Add(tempBooking);
    }

    return bookings;
}
于 2012-06-05T05:27:03.597 に答える