objDataTable.Columns.Add("Student Id", typeof(int));
objDataTable.PrimaryKey = "Student Id";
我已经尝试过很多方法,但是我做不到。
在C#中如何将主键设置为这一行?朋友们请帮忙。
先行谢过。
objDataTable.Columns.Add("Student Id", typeof(int));
objDataTable.PrimaryKey = "Student Id";
我已经尝试过很多方法,但是我做不到。
在C#中如何将主键设置为这一行?朋友们请帮忙。
先行谢过。
试试这个:
DataTable objDataTable = new DataTable();
objDataTable.Columns.Add("Student Id", typeof(int));
objDataTable.PrimaryKey = new DataColumn[] { objDataTable.Columns["Student Id"] };
该属性PrimaryKey
的类型为Type: System.Data.DataColumn[]
而非字符串。