why is this not working ? It’s something about the commandstring syntax near = but I can’t seem to figure it out, the online examples seem exactly the same.
Edit: Activated In is a column.
examples from How to select data from database with many filter options?
private void btnDist_Click(object sender, EventArgs e)
{
string cmdText = "SELECT * FROM Inventory WHERE Rep <> '#NA' AND Activated In = '#NA'";
SqlDataAdapter adapter = new SqlDataAdapter(cmdText, GetConnection());
DataSet distDS = new DataSet();
adapter.Fill(distDS);
dataGridView1.DataSource = distDS.Tables[0].DefaultView;
}
If the name of the column on your database is
Activated In(with a space) then you need to use square brackets when referring to the object / column name in queries, for example:This is because SQL treats spaces as a separator in the query language – square brackets are used to “escape” this (and other characters) in names.
Alternatively if the column is just called
Activatedthen you don’t need theINbit – either test for equality or test to see if the value is in a given range, but don’t do both.