0

I got error out of memory when i try to display the linQ result on data grid view Is there a limit of rows for Data Grid View ? I want to dispaly 41299440

This is the error message

A first chance exception of type 'System.OutOfMemoryException'
occurred in System.Drawing.dll

this is the linQ code

var sets =
    from a in patient
    from b in patient
    from c in patient
    from d in patient
    from l in patient
    where a.VisitNum < b.VisitNum 
          && b.VisitNum < c.VisitNum 
          && c.VisitNum < d.VisitNum 
          && d.VisitNum < l.VisitNum

    select new { a, b, c, d, l };

and this how i display the result

object[] buffer = new object[5];
List<DataGridViewRow> rows = new List<DataGridViewRow>();
foreach (var custObj in sets)
{
    buffer[0] = custObj.a.VisitNum;
    buffer[1] = custObj.a.ID;
    buffer[2] = patientname;
    buffer[3] = custObj.a.date;
    buffer[4] = description(Convert.ToInt32(custObj.a.RaId));
    rows.Add(new DataGridViewRow());
    rows[rows.Count - 1].CreateCells(dataGridView1, buffer);

    buffer[0] = custObj.b.VisitNum;
    buffer[1] = custObj.b.ID;
    buffer[2] = patientname;
    buffer[3] = custObj.b.date;
    buffer[4] = description(Convert.ToInt32(custObj.b.RaId));
    rows.Add(new DataGridViewRow());
    rows[rows.Count - 1].CreateCells(dataGridView1, buffer);

    buffer[0] = custObj.c.VisitNum;
    buffer[1] = custObj.c.ID;
    buffer[2] = patientname;
    buffer[3] = custObj.c.date;
    buffer[4] = description(Convert.ToInt32(custObj.c.RaId));
    rows.Add(new DataGridViewRow());
    rows[rows.Count - 1].CreateCells(dataGridView1, buffer);

    buffer[0] = custObj.d.VisitNum;
    buffer[1] = custObj.d.ID;
    buffer[2] = patientname;
    buffer[3] = custObj.d.date;
    buffer[4] = description(Convert.ToInt32(custObj.d.RaId));
    rows.Add(new DataGridViewRow());
    rows[rows.Count - 1].CreateCells(dataGridView1, buffer);

    buffer[0] = custObj.l.VisitNum;
    buffer[1] = custObj.l.ID;
    buffer[2] = patientname;
    buffer[3] = custObj.l.date;
    buffer[4] = description(Convert.ToInt32(custObj.l.RaId));
    rows.Add(new DataGridViewRow());
    rows[rows.Count - 1].CreateCells(dataGridView1, buffer);
    rows.Add(new DataGridViewRow());                           
}
dataGridView1.Rows.AddRange(rows.ToArray());

any suggestions?

4

0 回答 0