c# - How to programmatically set NullValue property of DataColumn of ADO.Net DataTable -


i have many new wizard-created datatables in project, need extract data from. there many string columns dbnull values in these tables, want extract empty strings.

so went ahead , changed nullvalue property of each datacolumn datatype of system.string (throw exception) (empty) this:

modifying nullvalue property of datacolumn in vs 2010

i got tired of repetitive work, tried set nullvalue programmatically in data layer of application.

i was, however, unable find property. decompiled code of system.data.datacolumn , property nullvalue did not seem exist there. nullvalue may magic feature of microsoft.vsdesigner.data.design.datacolumneditor, that's nothing more mere suspicion @ moment.

how can programmatically achieve same effect if did set nullvalue (empty) in property editor)?

yes. defaultvalue property of datacolumn not gonna work because have number of prepared datatables. here 1 possible solution => can place tables in 1 dataset (lets ds) first use following code:

for (int = 0; < ds.tables.count; i++)

{

       (int j = 0; j < ds.tables[i].columns.count; j++)           {               if(ds.tables[i].columns[j].datatype==typeof(string))               ds.tables[i].columns[j].defaultvalue = "empty string";            } 

}


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -