I call this method on form load ivent GetProducts(" "); This Query works fine in sql. It was working till i added WHERE When i use debugger on this line >> SqlDataReader myReader = cmd.ExecuteReader(); Can anyone advice me something?
public void GetProducts(string find)
{
try
{
using (SqlCommand cmd = new SqlCommand("SELECT ID, BarCode, ArtNumber, ProductName, Price, SelfPrice, PriceWithOutAWD, TotalSelfPrice, UnitsInStock, " +
" Comment, InputDateTime, InputQuantity, Margin, CategoryName, TypeName, ExpDate FROM GetProducts"+
"WHERE BarCode LIKE '%@F%' OR ArtNumber LIKE '%@F%' OR ProductName LIKE '%@F%' OR Price LIKE '%@F%' OR Comment LIKE '%@F%' ",
new SqlConnection(Program.ConnectionString)))
{
cmd.Parameters.AddWithValue("@F", find);
cmd.Connection.Open();
SqlDataReader myReader = cmd.ExecuteReader();
while (myReader.Read())
{
ProductTable.Rows.Add
(
(int)myReader["ID"],
myReader["BarCode"].ToString(),
myReader["ArtNumber"].ToString(),
myReader["ProductName"].ToString(),
(decimal)myReader["Price"],
(decimal)myReader["SelfPrice"],
(decimal)myReader["PriceWithOutAWD"],
myReader["TotalSelfPrice"].ToString(),
myReader["UnitsInStock"].ToString(),
myReader["Comment"].ToString(),
myReader["InputDateTime"].ToString(),
myReader["InputQuantity"].ToString(),
myReader["Margin"].ToString(),
myReader["CategoryName"].ToString(),
myReader["TypeName"].ToString(),
myReader["ExpDate"].ToString()
);
}
cmd.Connection.Close();
}
}
catch (Exception)
{
MessageBox.Show(Program.MsgError1, "Acid", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}