Configuring the primary key DataTable

objDataTable.Columns.Add("Student Id", typeof(int));
objDataTable.PrimaryKey = "Student Id";

am already tried many ways but i cant

in C # how to set the primary key in this line, friends, please help

thanks in advance

+4
source share
1 answer

Try the following:

DataTable objDataTable = new DataTable();
objDataTable.Columns.Add("Student Id", typeof(int));
objDataTable.PrimaryKey = new DataColumn[] { objDataTable.Columns["Student Id"] };

The property PrimaryKeyhas Type: System.Data.DataColumn[]no string.

+4
source

Source: https://habr.com/ru/post/1650265/


All Articles