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

javascript - Create websocket without connecting -

how to do line continuation in perl debugger for entering raw multi-line text (EOT)? -

Android SDK Manager freezes after installation of OSX 10.11 El Capitan public Beta -