PanPen120在CSDN上原创,如其他网站转载请注意排版和写明出处:
先反省一下:这段时间虽然接触MongoDB及工具箱里一些新的控件,和一些DataTable等新东西的时候主动加班,但是没有总结到csdn上来,多多总结,多多进步
关键字
DataTable
是什么?
类似于Excel的表格
怎么用?
//新建表 DataTable dt = new DataTable(); //定义表结构 dt.Columns.Add("Id", typeof(System.Int32));//列名 列所在数据类型 dt.Columns.Add("Name", typeof(System.String)); dt.Columns.Add("age", typeof(System.String)); //添加新行 for (int i = 0; i <= 3; i++) { DataRow dr = dt.NewRow(); //行 dr[0] = i; dr[1] = "wang" +i ; dr[2] = "5" + i; dt.Rows.Add(dr); //将行添加到DataTabl 格中``` }
怎么显示(怎么具体实用)
结合工具箱中的DataGridView
dataGridView1.DataSource= dt //控件.DataSource = ……(该控件可以直接绑定一个DataTable这样的表)
效果图