未处理的异常 - 无法绑定到DataSource上的属性或列pkid [英] Unhandled Exception - Cannot bind to the property or column pkid on the DataSource

查看:116
本文介绍了未处理的异常 - 无法绑定到DataSource上的属性或列pkid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行时遇到此错误,但在调试F5样式时没有...



关闭此表单时出错,这是一个MDI子表单。



在表单中一切正常,但在运行时你可以打开它并立即关闭它并获得未处理的异常



I get this error at runtime, but not while debugging F5 style...

Error occurs when closing this form, which is an MDI Child form.

Everything works fine while in the form, but in runtime you can open it and close it immediately and get the unhandled exception

Unhandled exception...

e.Exception.Message = Cannot bind to the property or column pkid on the DataSource.
Parameter name: dataMember

e.Exception.StackTrace =    at System.Windows.Forms.BindToObject.CheckBinding()
   at System.Windows.Forms.Binding.SetListManager(BindingManagerBase bindingManagerBase)
   at System.Windows.Forms.ListManagerBindingsCollection.AddCore(Binding dataBinding)
   at System.Windows.Forms.BindingsCollection.Add(Binding binding)
   at System.Windows.Forms.BindingContext.UpdateBinding(BindingContext newBindingContext, Binding binding)
   at System.Windows.Forms.Control.UpdateBindings()
   at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
   at System.Windows.Forms.ListControl.OnBindingContextChanged(EventArgs e)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.RecreateHandleCore()
   at System.Windows.Forms.ComboBox.RecreateHandleCore()
   at System.Windows.Forms.ComboBox.SetAutoComplete(Boolean reset, Boolean recreate)
   at System.Windows.Forms.ComboBox.OnDataSourceChanged(EventArgs e)
   at System.Windows.Forms.ListControl.SetDataConnection(Object newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
   at System.Windows.Forms.ListControl.DataSourceDisposed(Object sender, EventArgs e)
   at System.ComponentModel.Component.Dispose(Boolean disposing)
   at System.Windows.Forms.BindingSource.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.ComponentModel.Container.Dispose(Boolean disposing)
   at System.ComponentModel.Container.Dispose()
   at TOM.frmPODetail.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Form.WmClose(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

e.Exception.Source = System.Windows.Forms





为什么我会收到绑定错误当'关闭'表单超出我的知识时失败,更重要的是我必须想办法解决它。



以下是我的表格结束事件,以防万一是相关的,但我不这么认为,因为包含的例外没有捕捉/触发......



Why would i get an error that binding failed when 'closing' a form is beyond my knowledge, and more importantly I have to figure a way to fix it.

Below is my form closing event in case it is relevant, but I don't think so, as the included exception is not catching/triggering...

Private Sub frmPODetail_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Try
        Me.POBindingSource.EndEdit()
        Me.POLineBindingSource.EndEdit()
    Catch ex As Exception
        Dim reply As MsgBoxResult = MsgBox("Current row is in a bad state and cannot be saved, do you wish to exit and abort unsaved changes?", MsgBoxStyle.YesNoCancel + MsgBoxStyle.Critical)
        If reply = MsgBoxResult.No Or reply = MsgBoxResult.Cancel Then
            e.Cancel = True : Exit Sub
        Else
            e.Cancel = False : Exit Sub
        End If
    End Try

    e.Cancel = Not HandleSaveChangesResponse("closing")
End Sub





我无法进入代码查看它失败的地方,因为它在f5'ing时没有失败。试图得到行号但是失败了。





I can't step into the code to see where it fails, as it doesn't fail in while f5'ing. Tried to get line numbers but that's failing.

Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException

     Dim sw As IO.StreamWriter
     sw = New IO.StreamWriter("C:\tEMP\Unhandled-Detailed.txt", True)
     Dim st As StackTrace = New StackTrace(e.Exception, True)
     sw.WriteLine("Iterating through the Stack Frames...")
     For Each sf As StackFrame In st.GetFrames
         sw.Write("(Filename=" & sf.GetFileName & " Line " & sf.GetFileLineNumber() & ") Getmethod.module=" & sf.GetMethod.Module.ToString & " Getmethod=" & sf.GetMethod.DeclaringType.FullName.ToString & "." & sf.GetMethod.Name.ToString & vbCrLf)
     Next
     sw.Write(vbCrLf & vbCrLf)
     sw.Close()

     sw.Dispose()
     Process.Start("C:\tEMP\Unhandled-Detailed.txt")
 End Sub



输出......


outputs...

Iterating through the Stack Frames...
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindToObject.CheckBinding
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Binding.SetListManager
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListManagerBindingsCollection.AddCore
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindingsCollection.Add
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindingContext.UpdateBinding
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.UpdateBindings
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.OnBindingContextChanged
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListControl.OnBindingContextChanged
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.CreateControl
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.RecreateHandleCore
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ComboBox.RecreateHandleCore
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ComboBox.SetAutoComplete
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ComboBox.OnDataSourceChanged
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListControl.SetDataConnection
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListControl.DataSourceDisposed
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Component.Dispose
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindingSource.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Component.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Container.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Container.Dispose
(Filename= Line 0) Getmethod.module=TOM.exe Getmethod=TOM.frmPODetail.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Component.Dispose
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Form.WmClose
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control+ControlNativeWindow.WndProc
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.NativeWindow.Callback





任何帮助都将不胜感激。



Any help would be greatly appreciated.

推荐答案

好的,刚刚使用了我用于搜索过滤器的数据绑定组合框,进行了以下更改,现在我没有收到错误。



更改了使用表适配器和绑定源来获取代码中的数据表

Ok, just took a databound combobox that I was using for a search filter, made the following change, and now I don't get the error.

Changed from using a table adapter and binding source to grabbing a data table in code
Private Sub FillVendorSearchCombobox()
   Try
      Me.cmbSearchVendor.DataSource = DAL.VendorDataTableAllRecords
      cmbSearchVendor.ValueMember = "Pkid"
      cmbSearchVendor.DisplayMember = "Name"
   Catch ex As Exception
      MessageBox.Show("Can not open connection to populate the Service Crew Filter Combobox ! ")
   End Try
End Sub





来自一个功能



from a function

Public Function VendorDataTableAllRecords() As dsTOM.VendorDataTable
    Dim ta As New dsTOMTableAdapters.VendorTableAdapter
    Return ta.GetData
End Function


这篇关于未处理的异常 - 无法绑定到DataSource上的属性或列pkid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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