查看: 762|回复: 3
|
求助,如何set primary key in datatable
[复制链接]
|
|
Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow
objDT = New System.Data.DataTable("Member")
objDT.Columns.Add("ID", GetType(String))
objDT.Columns.Add("name", GetType(String))
objDT.PrimaryKey = 我要如何set primary key as "ID" 呢?
因为我可能需要execute以下的command
objDT.Rows.Find(ID).Delete() |
|
|
|
|
|
|
|
发表于 6-1-2007 07:54 PM
|
显示全部楼层
Primary Key 不是在 create table 的时候 set 的吗? |
|
|
|
|
|
|
|
楼主 |
发表于 7-1-2007 11:48 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 9-1-2007 05:14 PM
|
显示全部楼层
这是从 .Net 的 help 里找到的... 下次应该多多找 help:
private void SetPrimaryKeys(){
// Create a new DataTable and set two DataColumn objects as primary keys.
DataTable myTable = new DataTable();
DataColumn[] keys = new DataColumn[2];
DataColumn myColumn;
// Create column 1.
myColumn = new DataColumn();
myColumn.DataType = System.Type.GetType("System.String");
myColumn.ColumnName= "FirstName";
// Add the column to the DataTable.Columns collection.
myTable.Columns.Add(myColumn);
// Add the column to the array.
keys[0] = myColumn;
// Create column 2 and add it to the array.
myColumn = new DataColumn();
myColumn.DataType = System.Type.GetType("System.String");
myColumn.ColumnName = "LastName";
myTable.Columns.Add(myColumn);
// Add the column to the array.
keys[1] = myColumn;
// Set the PrimaryKeys property to the array.
myTable.PrimaryKey = keys;
} |
|
|
|
|
|
|
| |
本周最热论坛帖子
|