AccessViolatonException

vejita866

Member
Joined
Feb 25, 2012
Messages
15
Programming Experience
Beginner
Hello there!
i have a textbox with autocomplete mode suggested e autocompletesource customsource.
With Keypress event, i fill the customsource dinamically.
Randomly it happens that it thrown this exception (below the code)
can you help me?

chie.AutoCompleteSource = Windows.Forms.AutoCompleteSource.None chie.AutoCompleteCustomSource.Clear() Dim Database As New SQL.SQL Database.Login() Dim datatable As New DataTable Dim query As String = "" Select Case chie.Name Case "aggiungi_fumetti_testata" 'MsgBox("testata") query = "SELECT TOP 20 titolo FROM Testate where titolo LIKE '" & chie.Text.Replace("'", "''") & "%' AND id > 0" End Select If chie.Name Like "aggiungi_fumetti_nomeautore#" Then 'MsgBox("autore") query = "SELECT top 20 nome from autori WHERE nome like '" & chie.Text.Replace("'", "''") & "%' AND id > 0" End If datatable = Database.RiempiDataGrid(query) chie.AutoCompleteCustomSource.Clear() Dim r As DataRow For Each r In datatable.Rows chie.AutoCompleteCustomSource.Add(r.Item(0).ToString) Next chie.AutoCompleteSource = Windows.Forms.AutoCompleteSource.CustomSource
 
Your code is unreadable. Please post it again and this time use the 'vb' button on the advanced editor to wrap it in code formatting tags and not quote tags. Specify 'vb' as the option to use the VB code parser. You can also type the tags yourself if you want, e.g. [xcode=vb]your code here[/xcode]
 
Sorry :)

chie.AutoCompleteSource = Windows.Forms.AutoCompleteSource.None 
        chie.AutoCompleteCustomSource.Clear()
Dim Database As New SQL.SQL         
Database.Login()         
Dim datatable As New DataTable         
Dim query As String = ""         
Select Case chie.Name             
Case "aggiungi_fumetti_testata"
                  'MsgBox("testata")                 
  query = "SELECT TOP 20 titolo FROM Testate where titolo LIKE '" & chie.Text.Replace("'", "''") & "%' AND id > 0" 
        End Select         
If chie.Name Like "aggiungi_fumetti_nomeautore#" Then             
  'MsgBox("autore")             
  query = "SELECT top 20 nome from autori WHERE nome like '" & chie.Text.Replace("'", "''") & "%' AND id > 0"
         End If          
datatable = Database.RiempiDataGrid(query)         
chie.AutoCompleteCustomSource.Clear()         
Dim r As DataRow         
For Each r In datatable.Rows             
  chie.AutoCompleteCustomSource.Add(r.Item(0).ToString)         
Next         
chie.AutoCompleteSource = Windows.Forms.AutoCompleteSource.CustomSource 

 
Because of the fact that the code was unreadable, I didn't really look at the question too carefully.
With Keypress event, i fill the customsource dinamically.
That's crazy. The whole point of the AutoComplete is that you assign the list and the TextBox does the filtering for you based on what you type. You should just be getting all the data in the first place and then let the TextBox handle the rest.
 
i know that, but there are about 10.000 rows to insert into customsource. too many.
So i decided to fill it dinamycalli with maximum of 20 row. I dont think is crazy that kind of approach.
 
Back
Top