473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Searching with multiple textboxes.

80 64KB
So I've got a button that has to use 2 textboxes to search for 2 columns in my database.

Expand|Select|Wrap|Line Numbers
  1.  private void btnFilter_Click(object sender, EventArgs e)
  2.         {
  3.             SQLiteDataAdapter adap = new SQLiteDataAdapter("select * from Test", GetConnection());
  4.  
  5.             DataSet ds = new DataSet();
  6.             adap.Fill(ds);
  7.             dgvTable.DataSource = ds.Tables[0];
  8.  
  9.             DataTable dt = (DataTable)dgvTable.DataSource;
  10.             if (txtFilterChannel.Text != null && txtFilterLog.Text != null)
  11.             {
  12.                 dt.DefaultView.RowFilter = "Channel like '%" + txtFilterChannel.Text + "%'";
  13.                 dt.DefaultView.RowFilter = "LogName like '%" + txtFilterLog.Text + "%'";
  14.             }
  15.             else if (txtFilterChannel.Text != null && txtFilterLog.Text == null)
  16.             {
  17.                 dt.DefaultView.RowFilter = "Channel like '%" + txtFilterChannel.Text + "%'";
  18.             }
  19.             else if (txtFilterChannel.Text == null && txtFilterLog.Text != null)
  20.             {
  21.                 dt.DefaultView.RowFilter = "Logname like '%" + txtFilterLog.Text +"%'";
  22.             }
  23.  
  24.             CloseConnection();
  25.         }
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?
Jun 3 '13 #1
2 3148
Expand|Select|Wrap|Line Numbers
  1. rivate void btnFilter_Click(object sender, EventArgs e)
  2.         {
  3.             SQLiteDataAdapter adap = new SQLiteDataAdapter("select * from Test", GetConnection());
  4.  
  5.             DataSet ds = new DataSet();
  6.             adap.Fill(ds);
  7.             dgvTable.DataSource = ds.Tables[0];
  8.  
  9.             DataTable dt = (DataTable)dgvTable.DataSource;
  10.             if (txtFilterChannel.Text != null && txtFilterLog.Text != null)
  11.             {
  12.                 dt.DefaultView.RowFilter = "Channel like '%" + txtFilterChannel.Text + "%'";
  13.                 dt.DefaultView.RowFilter = "LogName like '%" + txtFilterLog.Text + "%'";
  14.             }
  15.             else if (txtFilterChannel.Text != null && txtFilterLog.Text == null)
  16.             {
  17.                 dt.DefaultView.RowFilter = "Channel like '%" + txtFilterChannel.Text + "%'";
  18.             }
  19.             else if (txtFilterChannel.Text == null && txtFilterLog.Text != null)
  20.             {
  21.                 dt.DefaultView.RowFilter = "Logname like '%" + txtFilterLog.Text +"%'";
  22.             }
  23.  
  24.             CloseConnection();
Jun 4 '13 #2
M1kkelZU
80 64KB
bump lol. Jin just reposted my exact code xD
Jun 6 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
2
by: Maarten | last post by:
hallow i have the folowing code to add somme textboxes comboboxes and checkboxes Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click...
7
by: Evil Homer | last post by:
How can i check if multiple textboxes have the same value?? Sure, i can do a bazillion if and else commands, but im sure it can be done in some easier way. For example, i have 3 (lets say three...
0
by: qudra | last post by:
Searching multiple records -------------------------------------------------------------------------------- Hi guys. I need ur help. In VB.NET we usually use this code to search the database...
0
by: Elmo Watson | last post by:
I've got quite a few textboxes on my page, along with labels, within a table. In these textboxes, I use the onTextChanged event (with autopostback=true) to calculate some formulas, and put the...
1
by: Peirski | last post by:
Hi all Situation: a form containing 10 textboxes with a button to validate those textboxes The user will have to complete these textboxes with numbers from 1 to 10 and each number can only...
1
by: flashguy | last post by:
In the form, i wanted to contain multiple textboxes that submits to the same field. However, when i start adding info to the text box, all other bounded textboxes for the same field will be mirrored....
4
by: Jan | last post by:
Hi there, I have a lot of textboxes in a form, i numberd them from from 1 til 10. for example: txtZpr1.text txtZpr2.text etc.. I want to fill these textboxes by using a loop. Is there...
7
by: =?Utf-8?B?Sm9lIFRob21wc29u?= | last post by:
Hi, I have a C# windows form application (.NET 2.0) that reads data over the serial port and displays the data via textboxes. I get a message 50 times/second. I know I can't update the screen...
4
by: harmony123 | last post by:
I would like to display the multiple records in multiple textboxes Following is my tables and data: tblJan with these data: col id 1 2 3 col January 10
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.