c# - Use DataTable.Load() without creating all column properties -


i'm loading data sql server database this:

sqlcommand cmd = new sqlcommand("select * x", conn); cmd.commandtype = commandtype.text; datatable dt = new datatable(); sqldatareader rd = cmd.executereader(); dt.load(rd, loadoption.preservechanges);  

issue:

the load() function initializes table columns columnname , datatype, looks deeper database, , adds constraints allowdbnull, autoincrement, maxlength, etc.

however, leads problems in application, because want further process data internally.

so, possible load() setting basic properties (which come directly select statement), without setting allowdbnull, maxlength, , on? or need clean these values after load() ? or there alternative calling load() ?

if don't want behaviour don't use datatable.load dbdataadapter.fill(datatable):

datatable dt = new datatable(); using(var da = new sqldataadapter("select * x", conn))     da.fill(dt); 

the fill operation adds rows destination datatable objects in dataset, creating datatable objects if not exist. when creating datatable objects, the fill operation creates column name metadata. however, if missingschemaaction property set addwithkey, appropriate primary keys , constraints created.

i have tested it, loads column-names , types, other properties allowdbnull or maxlength have default values might right or wrong.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -