从acess中读取数据然后显示到一个表格中
public void ShowWorkContentGrid(string dirCode, DataGridView gridView)
        {
            string sqlForSel = "select ID,Name from WorkContent where ItemCode='" + dirCode+"'";
            OleDbCommand cmd = new OleDbCommand(sqlForSel, conn);
            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                DataGridViewRow row = new DataGridViewRow();
                DataGridViewCell Cell1 = new DataGridViewTextBoxCell();
                Cell1.Value = reader[0];
                row.Cells.Add(Cell1);                Cell1 = new DataGridViewTextBoxCell();
                Cell1.Value = reader[1];
                row.Cells.Add(Cell1);                gridView.Rows.Add(row);
            }
            reader.Close();
        }
这么做 如果数据的条目量很多很多的话,表格显示的速度很慢
特别是频繁调用显示 就和死掉了一样
有什么好的方法不?

解决方案 »

  1.   

    直接将数据读到DataSet中,通过DataSet跟DataGridView绑定可以吧
      

  2.   

    DatagridView.datasource=datatable
    DatagridView.DataBind
      

  3.   

    动态加载吧,每次只显示部分数据。
    每次下拉后增加200条,通过sql语句控制数据,但需要解决好200条记录的获取方法。
    sql:
    select top 200 * from (select top @EndNum * from tb) as A order by id desc.