c# - Remove Spaces from SQL Results When Searching -
i have access database contains fields spaces in them. i'm trying allow user search matches spaces in results returning no information.
var dtcustomers = new datatable(); var adapter = new oledbdataadapter("select * devices [serial number]='" + textbox1.text + "'", conn); adapter.fill(dtcustomers); datagridview1.datasource = dtcustomers; foreach (datagridviewrow row in datagridview1.rows) { row.cells[0].style.forecolor = color.blue; row.cells[28].style.forecolor = color.red; }
the code above return results database if database has field that's entered '1z 4568 29z4h' won't returned unless user types that. results displayed in datagridview. there different query should using?
you can use sql's replace
function replace spaces in [serial number]
column nothing, , use textbox1.text.replace(' ','')
make sure user's input doesn't have spaces too:
var dtcustomers = new datatable(); var adapter = new oledbdataadapter(@"select * devices replace([serial number], " ", "")='" + textbox1.text.relpace(' ','') + "'", conn); adapter.fill(dtcustomers); datagridview1.datasource = dtcustomers; foreach (datagridviewrow row in datagridview1.rows) { row.cells[0].style.forecolor = color.blue; row.cells[28].style.forecolor = color.red; }
wiki
Comments
Post a Comment