private GetKeyValues ( |
||
key | ||
return | object[] |
// create a new DataTable DataTable table = new DataTable("myTable"); // add some columns table.Columns.Add("ID", typeof(int)); table.Columns.Add("Name", typeof(string)); table.Columns.Add("Email", typeof(string)); // add some rows table.Rows.Add(1, "John Smith", "[email protected]"); table.Rows.Add(2, "Jane Doe", "[email protected]"); // get the primary key values for the first row DataRow row = table.Rows[0]; DictionarykeyValues = row.GetKeyValues(); // display the primary key values foreach (KeyValuePair pair in keyValues) { Console.WriteLine("{0}: {1}", pair.Key, pair.Value); }
// create a new DataTable DataTable table = new DataTable("myTable"); // add a primary key column table.Columns.Add("ID", typeof(int)); table.PrimaryKey = new DataColumn[] { table.Columns["ID"] }; // add some rows table.Rows.Add(1); table.Rows.Add(2); // get the primary key values for the second row DataRow row = table.Rows[1]; DictionaryIn this example, we create a new DataTable with a primary key column. We then add some rows with primary key values and get the primary key values for the second row. We display the primary key values using a foreach loop. Package/Library: System.Data.dllkeyValues = row.GetKeyValues(); // display the primary key values foreach (KeyValuePair pair in keyValues) { Console.WriteLine("{0}: {1}", pair.Key, pair.Value); }