473,836 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a Textbox to filter from DataGridView and SQLite Database.

80 New Member
Hey all,
I'm trying to get some more user friendly things in my program done. Now I'm trying to filter by typing in a text box and it filters to what you are typing and shows the entire row.

This is what I currently have:
Expand|Select|Wrap|Line Numbers
  1. private void txtFilter_TextChanged(object sender, EventArgs e)
  2.         {
  3.             try
  4.             {
  5.                 SQLiteConnection connect = new SQLiteConnection(connString);
  6.                 connect.Open();
  7.                 string whereQuery = "select Channel from Test where Channel '" + txtFilter.Text + "'";
  8.                 SQLiteDataAdapter adap = new SQLiteDataAdapter(whereQuery, connString);
  10.                 DataSet ds2 = new DataSet();
  11.                 adap.Fill(ds2);
  12.                 dataGridView1.DataSource = ds2.Tables[0];
  13.             }
  14.             catch (Exception ex)
  15.             {
  16.                 MessageBox.Show("An error occured.\n" + ex.ToString(),"Error!");
  17.             }
  18.         }
I get an exception error though:
Expand|Select|Wrap|Line Numbers
  1. SQLite error
  2. near "'N'": syntax error
// N is what I started typing to start the filter.

I don't exactly get what I've done wrong.
Any help would be much appreciated. Thanks

Ok, so I've edited the code now to this:
Expand|Select|Wrap|Line Numbers
  1. private void txtFilter_TextChanged(object sender, EventArgs e) // FILTER TODO
  2.         {
  3.                 DataView view = new DataView();
  4.                 SQLiteConnection connect = new SQLiteConnection(connString);
  5.                 connect.Open();
  6.                 view.RowFilter = "Channel like '%" + txtFilter.Text + "%'";
  7.         }
No more exception errors, just not what I want it to do. It just keeps everything there. Any ideas?
Mar 11 '13
13 16589
80 New Member
Ah ok thanks, I really should be a bit more logical in these situations. thanks man :)
Mar 11 '13 #11
2 New Member
i have a similar issue but i would like to choose column via combobox

Expand|Select|Wrap|Line Numbers
  1.  dt.DefaultView.RowFilter = "product_name LIKE '%" + textBox4.Text + "%'";
that works fine but i want to use combobox1.text not product_name.
i have tried some knows formats but doesnt worked example

Expand|Select|Wrap|Line Numbers
  1. dt.DefaultView.RowFilter = "'"+comboBox1.Text+"' LIKE '%" + textBox4.Text + "%'";
need help on this thank you

compalte code is here (i have tried some other ways to do it but rowfilter just worked fine)

Expand|Select|Wrap|Line Numbers
  1.  set_connection();
  2.                 con.Open();
  3.                 com = con.CreateCommand();
  4.                 //string comtext = "SELECT * FROM products WHERE product_name LIKE'" + textBox4.Text + "'";
  5.                 //string comtext = "SELECT * FROM products WHERE product_name LIKE @pname";
  6.                 //com.Parameters.AddWithValue("@pname", "%Kar%");
  7.                 string comtext = "SELECT * FROM urunler";
  8.                 adapt = new SQLiteDataAdapter(comtext, con);
  9.                 ds.Reset();
  10.                 adapt.Fill(ds);
  11.                 dt = ds.Tables[0];
  12.                 dataGridView1.DataSource = dt;
  13.                 dt.DefaultView.RowFilter = "product_name LIKE '%" + textBox4.Text + "%'";
  14.                 //dt.DefaultView.RowFilter = "'"+comboBox1.Text+"' LIKE '%" + textBox4.Text + "%'";
  15.                 con.Close();
May 8 '19 #12
94 New Member
The single quotes you have around your column name is the issue. Try this:

Expand|Select|Wrap|Line Numbers
  1. dt.DefaultView.RowFilter = "[" + comboBox1.Text + "] LIKE '%" + textBox4.Text + "%'";
May 8 '19 #13
2 New Member
thank you so much! i was really stucked before [] thank you
May 8 '19 #14

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

Similar topics

by: dcrespo | last post by:
Hi all... Does anybody know about the best SQLite Database Manager open source web-based or standalone app under windows? I tried: - SQLiteManager (web-based - http://sqlitemanager.sourceforge.net/) but I can't get it working. (When I try to just create a new database, it does nothing... If anyone knows how to get it working, I am all ears (or eyes) :) )
by: Dan V. | last post by:
How can I use real SQL on a DataTable? i.e. not array of rows using a filter... as in DataTable.Select. I read at : microsoft.public.dotnet.framework.adonet "As others have posted: There is no SQL query processor for DataSets. You can use XPath with an XMLDataDocument built from the DataSet. You can also perform selections based on criteria, using the Find and Select methods, and you can create row filters using DataViews."
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are lost, and it reloads what was previously there. Any ideas? try {
by: Tulasi | last post by:
Hello, any one help me.I am new in SQLite database.My problem is that ,how SQLite Datebase is connected in Vb.Net?.Please Send me the source code because idont know the Connectionstring of SQLite database. This very urgent please help me.
by: Danny Nielsen | last post by:
Hi I am having trouble figuring out how to use combobox in a datagridview. What seemed to be a simple task turned out not to arrghh. I have a dataGridView with 4 columns, one of them is column ID (double). I want to be able to lookup a textual value using a combobox and - when choosed - replace this textual value with the corresponding ID ... the pulldownlist has a dataSource pointing to a table. It shows a text
by: martin1 | last post by:
Hi, All, DataGridView is populated with all coumns from database since i need some columns data for condition statement, after that I want to show rest of column in the DataGridView, so how to filter DataGridView column in order to show whatever column i want? Thanks
by: dillipdhal | last post by:
Hi This is Dillip from HSBC Software,Hyd. Now I m working in a financial domain. Please help me in "How can I insert data from a datagridview to database in vb .net and also retrive the data "
by: MFayaz | last post by:
Hello! I have to refresh datagridview when database update , IS there any way to solution that my datagridview auto refresh when any user update database. Thanks in Advance
by: Zabivb | last post by:
how to use mkdir to create dynamically folders using textbox ? coding ====== <?php $foldername="text"; mkdir = $foldername; ?>
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.