c# - How do I retrieve DataColumn.DefaultValue from a Sql Table? -
Is there a way to determine the default value of the column using ado.net from the SEL database? Tried using the FillSchema
method of
I SqlDataAdapter
:
using (SqlDataAdapter adapter = New SqlDataAdapter ()) {adapter.SelectCommand = myConnection CreateCommand (); Adapter. Select Comand Type = CommandType Text; Adapter.SelectCommand.CommandText = "Choose from MyTable"; Datatyal table = new datatelle (); Adapter.Fill (table); Adapter. Philsema (table, schema type map); } When I inspect DataTable
in DataColumns
, I can determine that any column is a AutoIncrement is
, and can determine whether it allows to tap using the AllowDBNull
property However, DefaultValue
(for columns which I know That is a default value) always null
. I considered:
Datatale schematic = zero; (SqlDataReader Reader = Adapter. Select select.ExecuteReader (CommandBehavior.SchemaOnly)) {schemaTable = reader.GetSchemaTable (); Reader.Close (); }
but not included in the DefaultValue
schema.
So ... I use the DefaultValue
column?
For information, use this question to query INFORMATION_SCHEMA
Are looking for:
SELECT TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'your table name' and 'COLUMN_NAME =' your column name ''
Mark
Comments
Post a Comment