473,749 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net - making combobox a search engine with mysql database

25 New Member
hi there,

I've been working on a movie library. I put a combobox on my form as a search engine. If user wants to search for a movie then type the title of the movie, all possible movie having that title will appear within the dropdown of the combobox. For example, if user typed letter m, all movies stored in the database having a title with m should appear automatically in the dropdown of combobox. If user wants to continue typing, ex. user typed ma, all movie title starting with ma will appear. It's already working. However, I'm getting error messages saying "Not allowed to chage the 'ConnectionStri ng' property while the connection (state = Open)." This error message appears everytime I'm typing more than one character on the combobox. It also appears when I deleted the string that I entered then typed a new one, but then, after displaying the error message, it still displays the result of what I typed before the error appeared. Here's the modified code:
Expand|Select|Wrap|Line Numbers
  1. Private mResetOnClear As Boolean = False
  2.     Public Property ResetOnClear() As Boolean
  3.         Get
  4.             Return mResetOnClear
  5.         End Get
  6.         Set(ByVal value As Boolean)
  7.             mResetOnClear = value
  8.         End Set
  9.     End Property
  10.  
  11.     Private Sub cmbMovies_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cmbMovies.KeyPress
  12.  
  13.         Try
  14.             Dim intIndex As Integer
  15.             Dim strEntry As String
  16.  
  17.             If Char.IsControl(e.KeyChar) Then
  18.                 If cmbMovies.SelectionStart <= 1 Then
  19.                     If mResetOnClear Then
  20.                         cmbMovies.SelectedIndex = 0
  21.                         cmbMovies.SelectAll()
  22.                     Else
  23.                         cmbMovies.Text = String.Empty
  24.                         cmbMovies.SelectedIndex = -1
  25.                     End If
  26.                     e.Handled = True
  27.                     Exit Sub
  28.  
  29.                 End If
  30.                 If cmbMovies.SelectionLength = 0 Then
  31.                     strEntry = cmbMovies.Text.Substring(0, cmbMovies.Text.Length - 1)
  32.                 Else
  33.                     strEntry = cmbMovies.Text.Substring(0, cmbMovies.SelectionStart - 1)
  34.  
  35.                 End If
  36.                 fetchData(strEntry)
  37.             ElseIf (Not Char.IsLetterOrDigit(e.KeyChar)) And (Not Char.IsWhiteSpace(e.KeyChar)) Then
  38.                 Exit Sub
  39.             Else
  40.                 If cmbMovies.SelectionLength = 0 Then
  41.                     strEntry = UCase(cmbMovies.Text & e.KeyChar)
  42.                 End If
  43.                 fetchData(strEntry)
  44.             End If
  45.  
  46.             intIndex = cmbMovies.FindString(strEntry)
  47.  
  48.             If intIndex <> -1 Then
  49.                 cmbMovies.SelectedIndex = intIndex
  50.                 cmbMovies.SelectionStart = strEntry.Length
  51.                 cmbMovies.SelectionLength = cmbMovies.Text.Length - cmbMovies.SelectionStart
  52.             Else
  53.                 cmbMovies.Focus()
  54.                 cmbMovies.Text = strEntry
  55.             End If
  56.             e.Handled = True
  57.             Exit Sub
  58.  
  59.         Catch ex As Exception
  60.             MessageBox.Show(ex.Message)
  61.         End Try
  62.     End Sub
  63.  
  64.     Private Sub fetchData(ByVal currentEntry As String)
  65.         Call Connect()
  66.         With Me
  67.  
  68.             Dim dt As DataTable
  69.             STRSQL = "SELECT idMovie, movieName From tblMovies"
  70.             Try
  71.                 cmbMovies.DataSource = Nothing
  72.  
  73.                 STRSQL = "Select idMovie, movieName FROM tblMovies Where movieName Like '" & currentEntry & "%'"
  74.  
  75.                 Dim myCmd As New MySqlCommand
  76.                 With myCmd
  77.                     .Connection = myConn
  78.                     .CommandText = STRSQL
  79.                     .CommandType = CommandType.Text
  80.                 End With
  81.                 Dim myAdptr As New MySqlDataAdapter(myCmd)
  82.                 dt = New DataTable
  83.                 myAdptr.Fill(dt)
  84.                 cmbMovies.DataSource = Nothing
  85.                 If (dt IsNot Nothing) Then
  86.                     If (dt.Rows.Count = 0) Then
  87.                         Me.Text = currentEntry
  88.                     End If
  89.  
  90.                     cmbMovies.ValueMember = "idMovie"
  91.                     cmbMovies.DisplayMember = "movieName"
  92.                     cmbMovies.DataSource = dt
  93.  
  94.                 End If
  95.             Catch ex As Exception
  96.                 MessageBox.Show(ex.Message)
  97.             End Try
  98.  
  99.         End With
  100.     End Sub
  101.  
I'm using mysql-connector-net-6.5.4 to connect the whole project to the database so I just called the Connect(). Any ideas would be greatly appreciated. I'm quite new to this as you can probably tell.


ps. sorry, I've already posted this question as a reply to the "
vb.net -- Enabling "Search" within a textbox..help me plzz" discussion. I've already posted my question before I noticed that the discussion was discussed last April 2009, I just thought that I should post my question as a new discussion. ^_^v
Jan 6 '13 #1
4 3329
PsychoCoder
465 Recognized Expert Moderator Contributor
You're trying to share the connection, then change it's properties while it's open. What does your Connect method look like?
Jan 7 '13 #2
kumsay
25 New Member
Expand|Select|Wrap|Line Numbers
  1. Imports MySql.Data.MySqlClient
  2.  
  3. Module Connection
  4.     Public myConnectionString As String
  5.     Public STRSQL As String
  6.     Public myConn As New MySqlConnection
  7.     Public Sub Connect()
  8.         With myConn
  9.             Try
  10.                 If .State = ConnectionState.Open Then
  11.  
  12.                 End If
  13.                 myConnectionString = "Database=movie_lib;Server=localhost;Uid=root;Password="
  14.                 .ConnectionString = myConnectionString
  15.                 .Open()
  16.                 'MsgBox("Successful Connection")
  17.             Catch ex As Exception
  18.                 MsgBox(ex.Message, MsgBoxStyle.Critical, "Connection Error")
  19.                 .Close()
  20.             End Try
  21.         End With
  22.     End Sub
  23.     Public Sub Disconnect()
  24.         With myConn
  25.             .Close()
  26.             .Dispose()
  27.         End With
  28.     End Sub
  29.  
  30. End Module
  31.  
that's my connection module look like sir
Jan 7 '13 #3
PsychoCoder
465 Recognized Expert Moderator Contributor
When you check if the connection is open you do nothing in this If statement

Expand|Select|Wrap|Line Numbers
  1. If .State = ConnectionState.Open Then
  2.  
  3. End If
So just close your connection

Expand|Select|Wrap|Line Numbers
  1. If .State = ConnectionState.Open Then
  2.    .Close()
  3. End If
Jan 7 '13 #4
kumsay
25 New Member
oh yeah!! it worked!!..why didn't I noticed that?? haha,thanks for the help sir :)
Jan 8 '13 #5

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

Similar topics

1
3144
by: michela rossi | last post by:
Hi, I currently have a website (running on RedHat Linux) comprising a large number of HTML files and PDF's. I currently use PHPMySearch (http://phpmysearch.web4.hm/index.php) which is a simple crawler, but is clever enough to crawl PDF's. I'd like to change one area of the site so that it's webform driven using a PHP/MySQL combo. This will allow me to provide a complex search to users that enables users to search for particular...
3
2265
by: Zaphod Beeblebrox | last post by:
As much of this question relates to mysql, it may be OT? I'm trying to make a search engine for a reasonably complex database that was originally developed by someone else in Access. I've ported the data to mySQL and am reasonably happy with everything except the performance I'm getting from queries with multpile joins. Although the database is fairly complex, it's not very large (less than 2 Mb as an Access db, less than that in mysql...
8
2613
by: Rod | last post by:
Hi, i am doing a ecommerce website and would like to implement a search engine to find products. All the serach engine I have found on the web are parsing html page! This is not what i want. i want to search within my mysql database. But using: - several columns (title, description) - several tables (the product table is linked with another table which
2
1365
by: Jordan | last post by:
I have a standard look to my site so I thought I might just make all the pages .asp pages and use #include statements to grab all the common content, however I want to be sure that all the big search engines crawl it without a problem. I heard that some have problems with ASP even if the ASP is not that complicated.
5
2495
by: Martien van Wanrooij | last post by:
I have been using phpdig in some websites but now I stored a lot of larger texts into a mysql database. In the phpdig search engine, when you entered a search word, the page where the search word was found was displayed with about 2 lines before and 2 lines behind the search word itself. Let us say you look for "peanut butter" an the word is found in a larger text about sandwiches, even when it is on the 40th line of the text you would get...
3
2657
by: hazly | last post by:
I'm very new in the web technology and need advice on search engine. I want to develop a portal using PHP and MySQL on Linux. Need to know on the following features : 1. search engine that could search my portal (mySQL, PDF, Ms Word & others) 2. search engine that could search to few web sites specified by user/programmer
19
2264
by: bb nicole | last post by:
Below is my search engine for job portal which jobseeker can find the job through quick search. But it cant work... Is it mysql query got problem?? Thanx.. Interface <html> <head> <title>UMS e-Job Portal</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body {
6
2871
by: impin | last post by:
thjis is my search form... <form name="form" action="search.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> this is my search.php
0
8832
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,...
0
9566
Oralloy
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...
0
9388
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 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...
1
9333
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,...
0
9254
tracyyun
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...
1
6800
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
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();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.