473,396 Members | 1,689 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,396 software developers and data experts.

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

25
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 'ConnectionString' 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 3301
PsychoCoder
465 Expert Mod 256MB
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
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 Expert Mod 256MB
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
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
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...
3
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...
8
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...
2
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...
5
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...
3
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...
19
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...
6
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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,...

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.