private void MakeTable(DataTable myTable){ // Create a DataTable. DataTable myTable = new DataTable("myTable"); // Create a DataColumn and set various properties. DataColumn myColumn = new DataColumn(); myColumn.DataType = System.Type.GetType("System.Decimal"); myColumn.AllowDBNull = false; myColumn.Caption = "Price"; myColumn.ColumnName = "Price"; myColumn.DefaultValue = 25; // Add the column to the table. myTable.Columns.Add(myColumn); // Add 10 rows and set values. DataRow myRow; for(int i = 0; i < 10; i++){ myRow = myTable.NewRow(); myRow["Price"] = i + 1; // Be sure to add the new row to the DataRowCollection. myTable.Rows.Add(myRow); } }
private void MakeTable(DataTable myTable){
// Create a DataTable. DataTable myTable = new DataTable("myTable");
// Create a DataColumn and set various properties.
DataColumn myColumn = new DataColumn();
myColumn.DataType = System.Type.GetType("System.Decimal");
myColumn.AllowDBNull = false;
myColumn.Caption = "Price";
myColumn.ColumnName = "Price";
myColumn.DefaultValue = 25;
// Add the column to the table.
myTable.Columns.Add(myColumn);
// Add 10 rows and set values.
DataRow myRow;
for(int i = 0; i < 10; i++){
myRow = myTable.NewRow(); myRow["Price"] = i + 1;
// Be sure to add the new row to the DataRowCollection.
myTable.Rows.Add(myRow);
}
}
DataTable dt=new DataTable();
dt.Columns.Add("aaaa",typeof(string));
dt.Rows.Add(new object[]{"value"});
string aaaa=dt.Rows[0]["aaaa"];