c# - OleDB Like query using DataAdapter -


below function goes database , pulls controlnumber similar 1 in database. can see commented out section near top, want replace last 3 digits of controlnumber wildcard indicators () way search database controlnumbers similar 1 below line ("1289**")

inside database, can use query "select * orders control_number '1298***';" , rewarded correct information. when try in code using method returned 0 rows.

any help?

note: going access database, not mysql

public string abscheckcontrolnumberforaccuracy(string _controlnumber,string _zip,string _state, string _city)         {             //_controlnumber = _controlnumber.remove(_controlnumber.length - 3) + "***";             _controlnumber = "1298***";             oledbconnection conn = new oledbconnection(straccessconntaxcert);              string query = "select * orders control_number @_controlnumber;";               oledbcommand cmd = new oledbcommand(query, conn);              cmd.commandtext = query;              oledbdataadapter adapter = new oledbdataadapter(query, conn);             adapter.selectcommand.parameters.add("@_controlnumber", oledbtype.varchar).value = "%" + _controlnumber + "%";                       system.data.datatable dt = new system.data.datatable();             try             {                 conn.open();                 adapter.fill(dt);             }              catch (system.exception ex)             {                                throw;             }                         {                 if (conn.state == connectionstate.open)                 {                     conn.close();                 }             }             return dt.rows[0][0].tostring();                     } 

use % wildcard character instead of *. % defacto wildcard. oledb driver translate wildcard character target database expects.

edit: have reread question. shouldn't use % should use ? instead. ? wildcard should use 1 character.

this means query should this

select * table foo '567???' 

also, try use parameters instead of string concatenation in query.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -