本文整理汇总了C#中System.Data.DataRow类的典型用法代码示例。如果您正苦于以下问题:C# DataRow类的具体用法?C# DataRow怎么用?C# DataRow使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataRow类属于System.Data命名空间,在下文中一共展示了DataRow类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNewDataRow
private void CreateNewDataRow()
{
// Use the MakeTable function below to create a new table.
DataTable table;
table = MakeNamesTable();
// Once a table has been created, use the
// NewRow to create a DataRow.
DataRow row;
row = table.NewRow();
// Then add the new row to the collection.
row["fName"] = "John";
row["lName"] = "Smith";
table.Rows.Add(row);
foreach(DataColumn column in table.Columns)
Console.WriteLine(column.ColumnName);
dataGrid1.DataSource=table;
}
private DataTable MakeNamesTable()
{
// Create a new DataTable titled 'Names.'
DataTable namesTable = new DataTable("Names");
// Add three column objects to the table.
DataColumn idColumn = new DataColumn();
idColumn.DataType = System.Type.GetType("System.Int32");
idColumn.ColumnName = "id";
idColumn.AutoIncrement = true;
namesTable.Columns.Add(idColumn);
DataColumn fNameColumn = new DataColumn();
fNameColumn.DataType = System.Type.GetType("System.String");
fNameColumn.ColumnName = "Fname";
fNameColumn.DefaultValue = "Fname";
namesTable.Columns.Add(fNameColumn);
DataColumn lNameColumn = new DataColumn();
lNameColumn.DataType = System.Type.GetType("System.String");
lNameColumn.ColumnName = "LName";
namesTable.Columns.Add(lNameColumn);
// Create an array for DataColumn objects.
DataColumn [] keys = new DataColumn [1];
keys[0] = idColumn;
namesTable.PrimaryKey = keys;
// Return the new DataTable.
return namesTable;
}