C# SQL Query Producing Different Results than Management Studio -


select      wl.watchlistid, wl.code, wl.[description], wl.datecreated,    wl.createdby, wl.datemodified, wl.modifiedby,    wpi.parameterexpression individualexpression,    wpb.parameterexpression businessexpression,    wpd.parameterexpression defaultexpression,    case         when exists(select 1 sourcewatchlist                     sourceid = @sourceid , watchlistid = wl.watchlistid)          1 else 0     end isactive     [watchlist] wl  left join      sourcewatchlist swl on wl.watchlistid = swl.watchlistid , swl.sourceid = @sourceid left join     (select          parameterexpression, sourceid, watchlistid      watchlistparameter      entitytype = 'individual') wpi on wpi.sourceid = @sourceid                                           , wpi.watchlistid = wl.watchlistid left join      (select           parameterexpression, sourceid, watchlistid       watchlistparameter       entitytype = 'business') wpb on wpb.sourceid = @sourceid                                          , wpb.watchlistid = wl.watchlistid left join      (select parameterexpression, sourceid, watchlistid       watchlistparameter       entitytype = 'default') wpd on wpd.sourceid = @sourceid                                         , wpd.watchlistid = wl.watchlistid       wl.isactive = 1 

i have above query. pretty simple.

here's snippet sql server management studio table :

enter image description here

and debugger in visual studio : enter image description here

the visual studio table has no data in 3 expression columns while management studio (correctly) does. can tell me why is, , steps can take resolve issue?

i'm 100% sure i've used same parameter between 2 well.

string sql = @"select  wl.watchlistid,wl.code,wl.[description],wl.datecreated,                                 wl.createdby,wl.datemodified,wl.modifiedby,                                 wpi.parameterexpression individualexpression,                                 wpb.parameterexpression businessexpression,                                 wpd.parameterexpression defaultexpression,                                 case when exists(select 1 sourcewatchlist                                      sourceid = @sourceid , watchlistid = wl.watchlistid)                                           1 else 0 end isactive                         [watchlist] wl                           left join  sourcewatchlist swl on wl.watchlistid = swl.watchlistid , swl.sourceid = @sourceid                         left join (select parameterexpression, sourceid, watchlistid watchlistparameter entitytype = 'individual') wpi                                         on wpi.sourceid = @sourceid , wpi.watchlistid = wl.watchlistid                         left join (select parameterexpression, sourceid, watchlistid watchlistparameter entitytype = 'business') wpb                                         on wpb.sourceid = @sourceid , wpb.watchlistid = wl.watchlistid                         left join (select parameterexpression, sourceid, watchlistid watchlistparameter entitytype = 'default') wpd                                         on wpd.sourceid = @sourceid , wpd.watchlistid = wl.watchlistid                         wl.isactive = 1";         sqlconnection conn = new sqlconnection(system.configuration.configurationmanager.connectionstrings["watchlistcompliance"].connectionstring);         conn.open();         sqlcommand cmd = new sqlcommand(sql, conn);         cmd.commandtext = sql;         cmd.parameters.addwithvalue("@sourceid", sourceid);          datatable dt = new datatable();         using (sqldataadapter = new sqldataadapter(cmd))         {             a.fill(dt);         } 

this might problem types , equality. can try using sqldatatype when define parameters on sqlcommand. when use addwithvalue without declaring type selecting wrong type. should use type declared in sql expression.

cmd.parameters.add("@sourceid", sqldbtype.varchar, 20); cmd.parameters["@sourceid"].value = sourceid; 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -