错误自动完成"AccessViolationException"; [英] Error AutoComplete "AccessViolationException"

查看:94
本文介绍了错误自动完成"AccessViolationException";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

对不起,我的英语,我是.Net编程的新手
我正在使用vb. net 2010框架4.我想创建自动完成文本框,但收到错误消息"AccessViolationException".规定:
2个使用自动完成文本框的文本框,每个文本框从一个数据库类型(SQL Server)检索到的数据不同但数据库不同.我知道的代码:

文本框1的第一个代码:
-------------------------

Dear All,

sorry for my english, I''m newbie in .Net programming
I am using vb. net 2010 framework 4. I want to make the autocomplete textbox but get error message "AccessViolationException". provisions:
2 pieces that use autocomplete textbox, textbox each data retrieved from a database type (sql server) but different databases. the code that I know:

First code of textbox 1 :
-------------------------

Call OpenInventory()
CommandInv.Connection = ConInv
CommandInv.CommandType = CommandType.Text
CommandInv.CommandText = "SELECT ART_NAME FROM ARTIST"
ObjDtAdapterInv.SelectCommand = CommandInv
ObjDtAdapterInv.Fill(objDataSetInv, "Artist")
ObjDtAdapterInv.Dispose()
Dim col As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To objDataSetInv.Tables("Artist").Rows.Count - 1
    col.Add(objDataSetInv.Tables("Artist").Rows(i)("ART_NAME").ToString())
Next
TBArtist.AutoCompleteSource = AutoCompleteSource.CustomSource
TBArtist.AutoCompleteCustomSource = col
TBArtist.AutoCompleteMode = AutoCompleteMode.Suggest
CommandInv.Dispose()
ObjDtAdapterInv.Dispose()
ConInv.Close()




文本框2的辅助代码:
----------------------------




secondary code of textbox 2:
----------------------------

Call OpenAuction()
CommandAuct.Connection = ConAuct
CommandAuct.CommandType = CommandType.Text
CommandAuct.CommandText = "SELECT cli_firstname FROM tclient WHERE cli_firstname LIKE '%" & TBOwner.Text & "%'"
ObjDtAdapterAuct.SelectCommand = CommandAuct
ObjDtAdapterAuct.Fill(objDataSetAuct, "Owner")
Dim ColOwner As New AutoCompleteStringCollection
 Dim i As Integer
For i = 0 To objDataSetAuct.Tables("Owner").Rows.Count - 1
ColOwner.Add(objDataSetAuct.Tables("Owner").Rows(i)("cli_firstname").ToString())
 Next
TBOwner.AutoCompleteSource = AutoCompleteSource.CustomSource
TBOwner.AutoCompleteCustomSource = ColOwner
TBOwner.AutoCompleteMode = AutoCompleteMode.Suggest
CommandAuct.Dispose()
ObjDtAdapterAuct.Dispose()
ConAuct.Close()



如果仅执行一个文本框,则在上面的代码正常运行;如果在第一个文本框之后执行,然后执行第二个文本框,则得到错误消息.请帮助紧急:(谢谢b4



The above code is running normal if only one textbox is executed, if executed after the first textbox and then executes the second textbox then get the error message. Please help urgent :( thanks b4

推荐答案

动态更改AutoCompleteSource存在问题.我假设您的辅助代码在用户键入时发生,例如TextChanged事件.
我听说将AutoCompleteSource设置为AutoCompleteSource.None,然后再重新分配新的源应该可以解决AccessViolation问题,但我自己还没有尝试过.
There are issues with changing the AutoCompleteSource on the fly. I am assuming your secondary code is happening as the user is typing i.e. TextChanged event.
I have heard that setting the AutoCompleteSource to AutoCompleteSource.None prior to re-assigning the new source should solve the AccessViolation issue but have not tried it myself.


这篇关于错误自动完成"AccessViolationException";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆