c# - "An expression of non-boolean type specified" error executing SQL from .Net -


i getting error:

an expression of non-boolean type specified in context condition expected, near 'likeram'.

i entered "ram" in txt_name:

sqlconnection con = new sqlconnection(                 @"data source=dell_laptop\sqlexpress;integrated security=true"); datatable dt = new datatable(); sqldataadapter sda = new sqldataadapter(                     "select * newproj name like" + txt_name.text, con); sda.fill(dt); datagridview1.datasource = dt; 

you're missing space between like , string concatentation , quotation mark around parameter:

sqldataadapter sda = new sqldataadapter(                string.format("select *                                newproj                                name '{0}'" txt_name.text), con); 

though i'd advise not use method prone sql injections. use sql parameters instead:

sqlcommand command = new sqlcommand("select * newproj name @text"); command.parameters.addwithvalue("text", txtname.text); var sqladapter = new sqldataadapter(command); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -