Question

i am trying to find the records based on the user input in msaccess database. below is the code

string strProvider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Employees.mdb";
string strSql = "SELECT * FROM tbl_employees where description like '" + txtsearch.Text.ToString() + "*'";

OleDbConnection con = new OleDbConnection(strProvider);
OleDbCommand cmd = new OleDbCommand(strSql, con);
con.Open();
cmd.CommandType = CommandType.Text;
OleDbDataReader dr = cmd.ExecuteReader();
int columnCount = dr.FieldCount;

When i ran the same query in my SQLView of msaccess i am getting records but when i ran it in VS i am not getting any records.

Was it helpful?

Solution

I think your matching should be changed:

String strSql = "SELECT * FROM tbl_employees WHERE description LIKE '" + txtsearch.Text.ToString() + "%'";

//Replaced * with %
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top