datagridview 有两列column1,column2 现在要绑定数据源string sqlzz = "select top 10 客户名称,服务业务员 from 客户管理表 ";
想把这个查询结果绑定到这两列中,不知道有没好的解决方法
现在我是把查询结果绑定给datatable ,然后再给datagridview 列赋值,这种方法如果数据量大会慢,求大虾指教
for (int i = 0; i < dt.Rows.Count; i++)
// {
// treeHeadDataGridView1.Rows.Add(); //先增加一行
// treeHeadDataGridView1.Rows[i].Cells["Column1"].Value = dt.Rows[i]["客户名称"].ToString(); //然后给单元格赋值
// treeHeadDataGridView1.Rows[i].Cells["Column2"].Value = dt.Rows[i]["服务业务员"].ToString();
// //dataGridView1.Rows[i].Cells["colSupport"].Value = list[i].Support;
// //dataGridView1.Rows[i].Cells["colBrand"].Value = list[i].Brand;
// //dataGridView1.Rows[i].Cells["colName"].Value = list[i].Name;
// }
想把这个查询结果绑定到这两列中,不知道有没好的解决方法
现在我是把查询结果绑定给datatable ,然后再给datagridview 列赋值,这种方法如果数据量大会慢,求大虾指教
for (int i = 0; i < dt.Rows.Count; i++)
// {
// treeHeadDataGridView1.Rows.Add(); //先增加一行
// treeHeadDataGridView1.Rows[i].Cells["Column1"].Value = dt.Rows[i]["客户名称"].ToString(); //然后给单元格赋值
// treeHeadDataGridView1.Rows[i].Cells["Column2"].Value = dt.Rows[i]["服务业务员"].ToString();
// //dataGridView1.Rows[i].Cells["colSupport"].Value = list[i].Support;
// //dataGridView1.Rows[i].Cells["colBrand"].Value = list[i].Brand;
// //dataGridView1.Rows[i].Cells["colName"].Value = list[i].Name;
// }
MySqlConnection conn;
MySqlDataAdapter myadp;
DataSet myds;
string MyConnectionString;
MyConnectionString = "server =localhost; uid =root; pwd =123456; database =test";
conn = new MySqlConnection();
conn.ConnectionString = MyConnectionString;
conn.Open();
myadp = new MySqlDataAdapter("select * from fx_user LIMIT " + i + ",10", conn);
myds = new DataSet();
myadp.Fill(myds, "table1");
this.dataGridView1.DataSource = myds.Tables["table1"];
dataGridView1.DataSource = dataGridView1.DataSource;
DataTable dt=new DataTable();
Gridview1.DataSource=dt;
Gridview1.DataBind();
Gridview1.DataBind();
dataGridView1.DataBind();
如果控件列和数据列不同通过筛选后绑定
如果控件列需经特殊处理(如:1\5\8列)通过循环赋值:http://blog.csdn.net/xianfajushi/article/details/8095375