Could someone help me, figure out why is that my new table always display the last row of data only.

the code goes like this:

string connection_string = @"Data Source=.;Initial Catalog=calendar;Integrated Security=True";
    SqlConnection conn;
    SqlCommand cmd;
    SqlDataReader dr;
    string cssMonth = "calMonth";
    int i = 0;
    string[] dateTo;
    string[] dateFrom;
    string[] events;

    private void displayCalendarEvents()
        TableRow tRow = new TableRow();
        TableCell cellMonth = new TableCell();
        TableCell cellDateTo = new TableCell();
        TableCell cellDateFrom = new TableCell();
        TableCell cellEvents = new TableCell();

        int num = setEvents(); // the number of selected events in the database i.e. 2 rows
        for (int i = 0; i < num; i++)
            tRow.CssClass = cssMonth;

            cellDateTo.Text = dateTo[i].ToString();
            cellDateFrom.Text = dateFrom[i].ToString();
            cellEvents.Text = events[i].ToString();



the "calendarTable" is an asp:Table control

here is the code for the setEvents() method

private int setEvents()
        int dataLength = 0;
        conn = new SqlConnection(connection_string);

        string strSelect = "SELECT dateFrom, dateTo, event FROM calendarevents";
        cmd = new SqlCommand(strSelect, conn);
        dr = cmd.ExecuteReader();
        if (dr.HasRows == true)
            i = 0;
            dataLength = countRows("calendarevents");
            dateFrom = new string[dataLength];
            dateTo = new string[dataLength];
            events = new string[dataLength];
            while (dr.Read())
                dateFrom[i] = dr["dateFrom"].ToString();
                dateTo[i] = dr["dateTo"].ToString();
                events[i] = dr["event"].ToString();
        return dataLength;        
This article has been dead for over six months. Start a new discussion instead.