这个是两个分别进行的过程
就是说绑定一下 datatable 然后再读入记录到textBox。
private void MakeDataTableAndDisplay(){
// Create new DataTable.
DataTable myDataTable = new DataTable("MyDataTable");
// Declare DataColumn and DataRow variables.
DataColumn myDataColumn;
DataRow myDataRow;
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.Int32");
myDataColumn.ColumnName = "id";
myDataTable.Columns.Add(myDataColumn);
// Create second column.
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "item";
myDataTable.Columns.Add(myDataColumn);
// Create new DataRow objects and add to DataTable.
for(int i = 0; i < 10; i++){
myDataRow = myDataTable.NewRow();
myDataRow["id"] = i;
myDataRow["item"] = "item " + i;
myDataTable.Rows.Add(myDataRow);
}
// Set to DataGrid.DataSource property to the table.
dataGrid1.DataSource = myDataTable;
}