I want to get the default values of all columns of a table so I can display them in the data-entry form, is there a way to do this using ADO.NET ? I know I can query the information_schema database for this info, I'm just wondering if there's a built-in way to do this in ADO.NET
+1
A:
Nope, you'll have to query the database schema, or hard code the values yourself.
Coding Gorilla
2010-09-10 19:37:49
A:
You can use DbConnection.GetSchema
to get the default column values:
DbConnection conn = SqlClientFactory.Instance.CreateConnection("server=.\\SQLEXPRESS;database=northwind;integrated security=true");
conn.Open();
DataTable schema;
try {
schema = conn.GetSchema("Columns", new string[4] { conn.Database, null, "products", null });
foreach (DataRow row in schema.Rows) {
Console.WriteLine("Name: {0}, Default: {1}", row["COLUMN_NAME"], row["COLUMN_DEFAULT"]);
}
} finally {
if (conn.State != ConnectionState.Closed)
conn.Close();
}
Max Toro
2010-10-15 18:57:43