但不知道用什么控件显示出来!请指教!
//--------------------初始化窗体,读入数据------------------
private void Form1_Load(object sender, System.EventArgs e)
{
this.sqlDataAdapter.Fill(DataTable);
this.dataGrid.DataSource = DataTable.DefaultView;
DataGridStateControl();
}
//--------------将数据显示在表格中,并设置表格参数------------------
private void DataGridStateControl()
{
DataGridTableStyle ts = new DataGridTableStyle();
DataGridNoActiveCellColumn aColumnTextColumn;
ts.AlternatingBackColor = Color.LightGray;
ts.MappingName = DataTable.TableName;
ts.AllowSorting = false;
int numCols = DataTable.Columns.Count;
for (int i = 0;i< numCols;i++)
{
aColumnTextColumn = new DataGridNoActiveCellColumn();
aColumnTextColumn.MappingName = DataTable.Columns[i].ColumnName;
aColumnTextColumn.HeaderText = DataTable.Columns[i].ColumnName;
aColumnTextColumn.NullText = "";
aColumnTextColumn.Format = "D";
ts.GridColumnStyles.Add(aColumnTextColumn);
}
this.dataGrid1.TableStyles.Add(ts);
this.dataGrid1.Select(0);
用你的表名替换一下,看看行不行