objDataTable.Columns.Add("Student Id", typeof(int));
objDataTable.PrimaryKey = "Student Id";
am already tried many ways but i can't
in c# how to set primary key to this line , friends please help
thanks in Advance
The primary key for a table is set by specifying an array of DataColumn objects from the table. The following example illustrates creating a primary key based on two columns: // set the primary key based on two columns in the DataTable DataTable dt = new DataTable("MyTable"); dt. Columns.
A database table commonly has a column or group of columns that uniquely identifies each row in the table. This identifying column or group of columns is called the primary key.
A primary key is the column or columns that contain values that uniquely identify each row in a table. A database table must have a primary key for Optim to insert, update, restore, or delete data from a database table.
Try this out :
DataTable objDataTable = new DataTable();
objDataTable.Columns.Add("Student Id", typeof(int));
objDataTable.PrimaryKey = new DataColumn[] { objDataTable.Columns["Student Id"] };
The property PrimaryKey
is of Type: System.Data.DataColumn[]
not string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With