我是Visual Basic的初学者,我正在使用Visual Basic 2012开发Visual Basic Windows应用程序。在允许用户添加/更新主客户记录的表单上,有一个允许用户搜索的组合框按客户编号记录。在此表单的Load事件期间,我尝试使用客户编号填充该组合框。当我在调试模式下执行下面的代码时,我注意到一旦执行了adapter.fill(table)行,就会出现错误/异常,代码结束。没有错误消息,代码也没有停止......它只是继续并加载表单的其余部分,但显然没有用数据填充组合框。
Private Sub frmMasterEntry_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.CenterToScreen()
'Initialize the controls on the form
InitializeForm()
'Fill the Drop-Down lists on the form
LoadComboBoxes()
'Initialize current master
CurrentMaster.Initialize()
'Testing binding data to a combo box
Try
Dim connection As New SqlConnection("Data Source=" & strServer & ";initial Catalog=" & strDatabase & ";persist security info=True;User ID=" & strUserName & ";Password=" & strPassword)
connection.Open()
Dim command As New SqlCommand("select * from AC_Master", connection)
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataSet()
adapter.Fill(table)
cboPolicySearch.DataSource = adapter
cboPolicySearch.DisplayMember = "MasterRefID"
cboPolicySearch.ValueMember = "MasterID"
Catch ex As Exception
MsgBox("Error loading the Policy Search ComboBox")
End Try
End Sub 'frmMasterEntry_Load
任何人都可以看到可能导致此adapter.fill行失败的原因吗?任何见解将不胜感激。感谢您的时间和考虑。
以下是原帖的更新: ex.message是" SELECT权限被拒绝在对象' AC_Master',数据库' AccountingCollections',schema' dbo'。"