简体   繁体   中英

DataGrid .Net compact framework

first of all sorry for my English.

I am working on .net compact framework project. I need to load data from database and then show this data in DataGrid. Can you give me some tips and tricks to improve perfomance. Is it better to fill data from adapter to DataSet -> DataTable -> DataGrid or from DataReader -> List -> DataGrid?

And how to improve loading a dig collection of data to DataGrid? (Paging or some other technique)

What part don't you understand?

class Form2 : Form {

  private static string SQLCONNECTION = @"Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;";

  private DataGrid dataGrid1;

  private void button_Click(object sender, EventArgs e) {
    var table = LoadData("SELECT FirstName, LastName FROM Employees;");
    dataGrid1.DataSource = table;
  }

  private DataTable LoadData(string sqlCmd) {
    var table = new DataTable();
    using (var cmd = new SqlCommand(sqlCmd, new SqlConnection(SQLCONNECTION))) {
      cmd.Connection.Open();
      table.Load(cmd.ExecuteReader());
      cmd.Connection.Close();
    }
    return table;
  }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM