4
I’m having a bit of an amateur problem here.
I’m not getting this SELECT
from 2 CONDITIONS, and I can’t find the ERROR! Someone please give me a light there!
Follows the Code:
OleDbConnection Con = new OleDbConnection();
Con.ConnectionString = Properties.Settings.Default.dbConnection;
Con.Open();
OleDbCommand Cmm = new OleDbCommand();
Cmm.CommandText = "SELECT CodAutomaticProd, DescProd, BrandCod FROM tbProdutos WHERE ModelProd LIKE '%" + txtModel.Text + "%' AND YearProd LIKE '%" + txtYear.Text + " %' ";
Cmm.CommandType = CommandType.Text;
Cmm.Connection = Con;
OleDbDataReader DR;
DR = Cmm.ExecuteReader();
listBox1.Items.Clear();
while (DR.Read())
{
listBox1.Items.Add(DR.GetInt32(0) + " - " + DR.GetString(1) + " - " + DR.GetString(2));
}
The code runs perfectly inside the BANK, and is inside the TRY
which does not indicate ERROR by "Exception".
What would be the mistake? You shouldn’t be concatenating
string
s. Should be using parameters.– Leonel Sanches da Silva
Is your select working if it is run directly in the bank? Is your code inside a Try/catch block? If yes check what the catch message says and post in your question.
– Joao Paulo
Gypsy, the program is not indicating error itself, it just doesn’t bring the information. It’s probably something from AND, because when you put only 1 condition to "Modelprod" it brings the information perfectly.
– Maurício Sanches
See about injection of SQL.
– Victor Stafusa
And also this: https://xkcd.com/327/
– Victor Stafusa