c# - How to pass a string inside a query -
i have pass string value inside query...here code
string = configurationmanager.appsettings["var"]; sqldataadapter da = new sqldataadapter("select codesnippet edk_custombrsnippet_vw partnerid = 'a'", con); datatable dt = new datatable(); da.fill(dt);
i got value in string a..but dont know how pass string in query..any suggestion?
use parameterized query, example:
string = configurationmanager.appsettings["var"]; sqldataadapter da = new sqldataadapter( "select codesnippet edk_custombrsnippet_vw partnerid = @partnerid", con); da.selectcommand.parameters.addwithvalue("@partnerid", a); datatable dt = new datatable(); da.fill(dt);
you should not embed string value sql - opens sql injection attacks. admittedly in case it's not user-provided value, it's still better not include directly.
edit: adapted example this msdn page appears sqldataadapter
doesn't have parameters
property far can see. i've therefore adapted use sqldataadapter.selectcommand.parameters
i'd expect work... may need tweak slightly.
Comments
Post a Comment