c# - SQLDataAdapter changing value type returned from SQL -
in c# project, executing query against sql 2014 database retrieve employee
data, including periodend
stored in database decimal
(i.e., nov 17, 2016 stored 20161117). database querying not our product cannot change type datetime
field.
here sql script being executed:
select distinct e.employee empno, ch.perend periodend, ch.prpoststat upempl e inner join upchkh ch on e.employee = ch.employee ch.perend = @periodend
here sqldataadapter
call:
executesqlcommandscript(string sqlscript, list<sqlparams> sqlparams) { . . . (setup sqlconnection info) using (sqlconnection _conn = new sqlconnection(connectionstring)) { using (sqlcommand _cmd = new sqlcommand()) { _cmd.commandtext = sqlscript; _cmd.connection = _conn; _cmd.connection.open(); // add sqlparameters sql command if (sqlparams != null) { _cmd.parameters.addrange(sqlparams.toarray()); } using (sqldataadapter _sqldataadapter = new sqldataadapter(_cmd)) { try { // save table info results object dataset _dataset = new dataset(); _sqldataadapter.fill(_dataset); sqlresult _result = new sqlresult(); _result.dataset = _dataset; _result.tablecount = _dataset.tables.count; this.results.add(_result); } } } } }
using sql server profiler can see query passed sql is:
exec sp_executesql n' select distinct e.employee empno, ch.perend periodend, ch.prpoststat upempl e inner join upchkh ch on e.employee = ch.employee ch.perend = @periodend ',n'@periodend nvarchar(8)',@periodend=n'20161101'
if run directly in sql these reults:
however, results of datatable
created _sqldataadapter
is:
is there way force sqldataadapter
use data type in results? or possible sql indeed returning datetime
object instead of decimal
(the periodend
column defined in sql decimal(9,0)
)? if there reason and/or way prevent it?
try , add column type explicitly when creating dataset , adding datacolumn of type decimal datatable. guess since not explicitly specifying column type, .net deriving value.
Comments
Post a Comment