zaterdag 3 oktober 2009

Get a table's primary keys

DataSet data = new DataSet();
SqlConnection connection = new SqlConnection(Properties.Settings.Default.connectionString);
SqlCommand command = new SqlCommand();
string commandtext = "SELECT TOP 1 * FROM " + tabelName;
command.CommandText = commandtext;
command.Connection = connection;
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.FillSchema(data, SchemaType.Source);

DataColumn[] pks = data.Tables[0].PrimaryKey;

Geen opmerkingen:

Een reactie posten