When I type '
in my TextBox, it's resulting an error. I know that because the '
is part of SQL Query. How do I avoid that? I've done it with Parameter, but didn't even work.
private void theFilter(string FilterValue) {
string thisQuery = "SELECT * FROM [Customer] WHERE CONCAT([Name], [Address], [Discount]) LIKE '%" + @FilterValue + "%'";
using(SqlConnection thisSqlConnection = new SqlConnection(theConnectionString))
using(SqlCommand thisSqlCommand = new SqlCommand(thisQuery, thisSqlConnection)) {
thisSqlCommand.Parameters.AddWithValue("@FilterValue", FilterValue);
using(SqlDataAdapter thisSqlDataAdapter = new SqlDataAdapter(thisSqlCommand))
using(DataTable thisDataTable = new DataTable()) {
thisSqlDataAdapter.Fill(thisDataTable);
DataGrid_Customer.ItemsSource = thisDataTable.DefaultView;
}
}
}