So I've got a button that has to use 2 textboxes to search for 2 columns in my database.
My Current code for it.
The GetConnection() ; and the CloseConnection (); Methods are just making a new connection and closing that connection, if needed I can post that code too later.
But basically, It only "filters" 1 textbox but if I say I want to search the Channel and the Log in which it is in, it doesn't search anything and returns all data in the database.
Any ideas? Or am I using the wrong way to show this?
Code:
private void btnFilter_Click(object sender, EventArgs e)
{
SQLiteDataAdapter adap = new SQLiteDataAdapter("select * from Test", GetConnection());
DataSet ds = new DataSet();
adap.Fill(ds);
dgvTable.DataSource = ds.Tables[0];
DataTable dt = (DataTable)dgvTable.DataSource;
if (txtFilterChannel.Text != null && txtFilterLog.Text != null)
{
dt.DefaultView.RowFilter = "Channel like '%" + txtFilterChannel.Text + "%'";
dt.DefaultView.RowFilter = "LogName like '%" + txtFilterLog.Text + "%'";
}
else if (txtFilterChannel.Text != null && txtFilterLog.Text == null)
{
dt.DefaultView.RowFilter = "Channel like '%" + txtFilterChannel.Text + "%'";
}
else if (txtFilterChannel.Text == null && txtFilterLog.Text != null)
{
dt.DefaultView.RowFilter = "Logname like '%" + txtFilterLog.Text +"%'";
}
CloseConnection();
}
The GetConnection() ; and the CloseConnection (); Methods are just making a new connection and closing that connection, if needed I can post that code too later.
But basically, It only "filters" 1 textbox but if I say I want to search the Channel and the Log in which it is in, it doesn't search anything and returns all data in the database.
Any ideas? Or am I using the wrong way to show this?
Comment