I joined C# Developer today and this is my first post. Hello to all!
I am creating a database with MS Access as my back-end and C# Win Form using VS 2017 as my front-end. I am having issues with deleting rows in my table using the DELETE clause.
Background info:
A user enters a search term in a text box named Srch_Txtbx and clicks search button where my DataGridView list is filtered based on the user's search text. So any row in any of the columns within the DataGridView that has the user's search term is kept while all others are filtered out. I then delete the rows not equal to the user's text entry in a separate temporary table (copy of original). BTW, I am using a copy (temporary table) of the original table because I am deleting rows based on text box and combobox selections. Using the temp table allows me to filter my comboboxes based on the other comboboxes and text box selections but the problem I'm having is that only the rows that are like the text entry are being deleted.
As a simple example:
User enters search term: BIT-1000
My DataGridView filters correctly showing only one row corresponding to the TAG_NAME column. My temporary table should be exactly the same showing only one row containing the TAG_NAME BIT-1000. Instead it deletes all rows where the TAG_NAME starts with BIT but keeps the BIT-1000 row and all other rows where the TAG_NAME doesn't start with BIT. See my code below. I'm using the <> operator but is not working correctly. I also tried using NOT LIKE instead of <> and that gives me the same result as <>. What am I doing wrong?
Here is my code:
using (OleDbCommand cmd = dbConn.CreateCommand())
{
dbConn.Open();
cmd.CommandText = "DELETE FROM [Temp_Tbl] " +
"WHERE [IO_CARD] <> '" + Srch_Txtbx.Text + "'" +
" AND [PLC_PANEL] <> '" + Srch_Txtbx.Text + "'" +
" AND [SLOT_NO] <> '" + Srch_Txtbx.Text + "'" +
" AND [CHANNEL_NO] <> '" + Srch_Txtbx.Text + "'" +
" AND [TAG_NAME] <> '" + Srch_Txtbx.Text + "'";
cmd.Connection = dbConn;
cmd.ExecuteNonQuery();
dbConn.Close();
}
I am creating a database with MS Access as my back-end and C# Win Form using VS 2017 as my front-end. I am having issues with deleting rows in my table using the DELETE clause.
Background info:
A user enters a search term in a text box named Srch_Txtbx and clicks search button where my DataGridView list is filtered based on the user's search text. So any row in any of the columns within the DataGridView that has the user's search term is kept while all others are filtered out. I then delete the rows not equal to the user's text entry in a separate temporary table (copy of original). BTW, I am using a copy (temporary table) of the original table because I am deleting rows based on text box and combobox selections. Using the temp table allows me to filter my comboboxes based on the other comboboxes and text box selections but the problem I'm having is that only the rows that are like the text entry are being deleted.
As a simple example:
User enters search term: BIT-1000
My DataGridView filters correctly showing only one row corresponding to the TAG_NAME column. My temporary table should be exactly the same showing only one row containing the TAG_NAME BIT-1000. Instead it deletes all rows where the TAG_NAME starts with BIT but keeps the BIT-1000 row and all other rows where the TAG_NAME doesn't start with BIT. See my code below. I'm using the <> operator but is not working correctly. I also tried using NOT LIKE instead of <> and that gives me the same result as <>. What am I doing wrong?
Here is my code:
using (OleDbCommand cmd = dbConn.CreateCommand())
{
dbConn.Open();
cmd.CommandText = "DELETE FROM [Temp_Tbl] " +
"WHERE [IO_CARD] <> '" + Srch_Txtbx.Text + "'" +
" AND [PLC_PANEL] <> '" + Srch_Txtbx.Text + "'" +
" AND [SLOT_NO] <> '" + Srch_Txtbx.Text + "'" +
" AND [CHANNEL_NO] <> '" + Srch_Txtbx.Text + "'" +
" AND [TAG_NAME] <> '" + Srch_Txtbx.Text + "'";
cmd.Connection = dbConn;
cmd.ExecuteNonQuery();
dbConn.Close();
}