You can set the primary key of the table:
Dim table As New DataTable() table.Columns.Add(New DataColumn("MyColumn")) Dim primaryKey(1) As DataColumn primaryKey(1) = table.Columns("MyColumn") table.PrimaryKey = primaryKey
To be able to use the primary key, you need to make sure that all values ββfor this column are unique.
I mainly work in C # and have a couple of extension methods that I use to "organize" the calls I need to make, which you can consider by translating to VB and using:
public static void SetPrimaryKey(this DataTable value, string columnName) { value.PrimaryKey = new DataColumn[] { value.Columns[columnName] }; } public static DataRow FindByPrimaryKey(this DataTable value, object key) { return value.Rows.Find(key); }
Rob
source share