Maintainging default values when importing a sql database into a vb.net application
I am trying to copy a sql database into a vb.net application however it is not maintaining the default values when I do this. Is it possible to import the default values and have them automatically assigned when creating a new row or do I have to manually assign the default v开发者_如何学JAVAalues again in my code?
I assume you're databinding your data on a grid control? Default values are only known to the database and are only used if you send an INSERT statement without data for the column that the default constraint is on. This means you have to manually set the default value if you want it to be visual in your application before you insert your data.
You can in fact retrieve the default value from the database, but these values are presented as a SQL formula (nvarchar) so you'd have to execute them in order to get an actual value (e.g.: default "0" would be stored as "(0)")
select COLUMN_DEFAULT from INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA = 'abc' and TABLE_NAME = 'def' and COLUMN_NAME = 'ghi'
精彩评论