Hello to everyone!I'm developing a C# application that manages an Access database. In order to perform a word search within the database registers, I have used a SQL command based on the 'LIKE' condition. I attach the complete code below: myConnection.Open(); OleDbDataAdapter adapt_pregunta = new OleDbDataAdapter(); string query_c = String.Format("SELECT * FROM PREGUNTA WHERE TEMA LIKE '*{0}*' OR NUM_TEMA LIKE '*{1}*' OR AUTOR LIKE '*{2}*' OR ENUNCIAT LIKE '*{3}*'", text, text, text,text); OleDbCommand comm_preg = new OleDbCommand(query_c, myConnection); adapt_pregunta.SelectCommand = comm_preg; OleDbCommandBuilder cb_preg = new OleDbCommandBuilder(adapt_pregunta); DataSet ds_preg = new DataSet("PREGUNTA"); adapt_pregunta.Fill(ds_preg, "PREGUNTA"); DataTable dt_preg = ds_preg.Tables[0]; myConnection.Close();
Where the final SQL command is:SELECT * FROM PREGUNTA WHERE TEMA LIKE '*3*' OR NUM_TEMA LIKE '*3*' OR AUTOR LIKE '*3*' OR ENUNCIAT LIKE '*3*'
Although the command works properly if I manually insert it as a new query in MS Access, it does not work with the previous code. The DataTable is not filled.I have tried a simple "SELECT * FROM PREGUNTA" command so to check if it was a code problem, and surprisingly, it works well. Does anybody know where the problem is?Thanks.Marc