This is the code I have:
private void btnSearch_Click(object sender, RoutedEventArgs e)
{
using (SqlConnection sc = new SqlConnection(sConn))
{
sc.Open();
string SearchFor = txtSearch.Text;
using (SqlDataAdapter adapter = new SqlDataAdapter())
{
DataTable dt = new DataTable();
grdData.ItemsSource = dt.DefaultView.RowFilter = string.Concat("SELECT * FROM Student WHERE Forename LIKE '%", SearchFor, "%'");
}
When I run the code I get:
"Syntax error: Missing operand after 'Student' operator."
I'm using WPF... I want it so I can search for people by just typing a letter of their name what can I do?
You need to fill your
DataTable
first with some data and then you can filter resultsor filter in SQL without
RowFilter
In your filter, you only need to specify the WHERE clause, it's not a full SQL SELECT statement that is needed. So it should look like this:
Be aware though, that a user could enter some characters like
%
,'
etc.please change as below..
The "RowFilter" query is not a complete SQL query but rather a subset of a SQL query. In your case you want something like:
For future reference: MSDN Documentation.