本帖最后由 darthhiker 于 2010-06-29 02:06:38 编辑

解决方案 »

  1.   

    this.bindingSource.DataSource=_dataSet;
      this.bindingSource.DataMember=_dataSet.Tables[0].TableName;
      this.dataGridView.DataSource = _dataSet;
    还没有试过调用2次DataSource
      

  2.   

    代码应该是
    this.bindingSource.DataSource=_dataSet;
      this.bindingSource.DataMember=_dataSet.Tables[0].TableName;
      this.dataGridView.DataSource = this.bindingsource;
    笔误了。
      

  3.   

    第一个错的详细错误信息未处理 System.Reflection.TargetInvocationException
      Message="调用的目标发生了异常。"
      Source="mscorlib"
      StackTrace:
           在 System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
           在 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
           在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
           在 System.Delegate.DynamicInvokeImpl(Object[] args)
           在 System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
           在 System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
           在 System.Threading.ExecutionContext.runTryCode(Object userData)
           在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
           在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
           在 System.Windows.Forms.Control.InvokeMarshaledCallbacks()
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 DevExpress.XtraEditors.Container.EditorContainer.WndProc(Message& m)
           在 DevExpress.XtraGrid.GridControl.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.Run(Form mainForm)
           在 AnalysisClient.Program.Main() 位置 C:\Users\Administrator\Documents\Visual Studio 2008\Projects\AnalysisProject\AnalysisClient\Program.cs:行号 17
           在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           在 System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
           在 System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
           在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
           在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
           在 System.Activator.CreateInstance(ActivationContext activationContext)
           在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
           在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.ArgumentNullException
           Message="键不能为空。\r\n参数名: key"
           Source="mscorlib"
           ParamName="key"
           StackTrace:
                在 System.Collections.Hashtable.get_Item(Object key)
                在 DevExpress.Data.Helpers.BaseRowsKeeper.Restore(Object rowKey, Object row)
                在 DevExpress.Data.Helpers.ListSourceRowsKeeper.RestoreSelection(Int32 count, Boolean needRestoreGrouping, Boolean needRestoreSelection)
                在 DevExpress.Data.Helpers.ListSourceRowsKeeper.RestoreCore()
                在 DevExpress.Data.Helpers.ListSourceRowsKeeper.RestoreCore(Boolean clear)
                在 DevExpress.Data.Helpers.ListSourceRowsKeeper.Restore()
                在 DevExpress.Data.DataController.DoRefreshCore(Boolean useRowsKeeper)
                在 DevExpress.Data.DataController.DoRefresh(Boolean useRowsKeeper)
                在 DevExpress.Data.CurrencyDataController.DoRefresh(Boolean useRowsKeeper)
                在 DevExpress.Data.DataControllerBase.DoRefresh()
                在 DevExpress.Data.DataController.OnBindingListChangedCore(ListChangedEventArgs e)
                在 DevExpress.Data.CurrencyDataController.OnBindingListChangedCore(ListChangedEventArgs e)
                在 DevExpress.Data.DataController.OnBindingListChanged(ListChangedEventArgs e)
           InnerException: 
      

  4.   

    第二个错的未处理 System.InvalidOperationException
      Message="BindingSource 不能是自己的数据源。请不要将 DataSource 和 DataMember 属性设置为循环引用 BindingSource 的值。"
      Source="System.Windows.Forms"
      StackTrace:
           在 System.Windows.Forms.BindingSource.get_Count()
           在 DevExpress.Data.Helpers.BaseListDataControllerHelper.GetRow(Int32 listSourceRow)
           在 DevExpress.Data.Helpers.BaseDataViewControllerHelper.GetDataRowCore(Int32 listSourceRow)
           在 DevExpress.Data.Helpers.BaseDataViewControllerHelper.GetDataRow(Int32 listSourceRow)
           在 DevExpress.Data.Helpers.BaseDataViewControllerHelper.GetRowKey(Int32 listSourceRow)
           在 DevExpress.Data.DataController.GetRowKey(Int32 controllerRow)
           在 DevExpress.XtraGrid.Views.Base.ColumnView.GetRowKey(Int32 rowHandle)
           在 DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.LoadRows(GridRowsLoadInfo e)
           在 DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.Calc(Graphics g, Rectangle bounds)
           在 DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.FullRecalcScroll(Graphics g, Rectangle bounds)
           在 DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcAfterVertScrollCore(Graphics g, Rectangle bounds, Boolean useCache)
           在 DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcAfterVertScroll(Graphics g, Rectangle bounds, Boolean useCache)
           在 DevExpress.XtraGrid.Views.Grid.GridView.RefreshRows(Boolean useCache, Boolean afterScroll)
           在 DevExpress.XtraGrid.Views.Grid.GridView.CalculateDataCore()
           在 DevExpress.XtraGrid.Views.Grid.GridView.CalculateData()
           在 DevExpress.XtraGrid.Views.Base.BaseView.CheckViewInfo()
           在 DevExpress.XtraGrid.Views.Base.BaseView.Draw(GraphicsCache e)
           在 DevExpress.XtraGrid.GridControl.OnPaint(PaintEventArgs e)
           在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
           在 System.Windows.Forms.Control.WmPaint(Message& m)
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 DevExpress.XtraEditors.Container.EditorContainer.WndProc(Message& m)
           在 DevExpress.XtraGrid.GridControl.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.Run(Form mainForm)
           在 AnalysisClient.Program.Main() 位置 C:\Users\Administrator\Documents\Visual Studio 2008\Projects\AnalysisProject\AnalysisClient\Program.cs:行号 17
           在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           在 System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
           在 System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
           在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
           在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
           在 System.Activator.CreateInstance(ActivationContext activationContext)
           在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
           在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ThreadHelper.ThreadStart()
      InnerException: 
      

  5.   

    主键重复了,你看看你web服务获取的数据源是不是又重复的主键,我以前也遇到过,大概就是这个问题引起的
      

  6.   

    对的,就是dev的控件,我以前做过一个查询中心,就是有重复的主键后出现了类似问题。
      

  7.   

    如果是,楼主可以把主健重新NEW下试试~
      

  8.   

    数据的主键都是guid的,应该不会重复把,新增记录的主键是Guid.NewGuid()的
      

  9.   

    问题似乎解决了,加了个databind的delegate,然后用invoke调用databind就不报错了。
      

  10.   

    研究了几天,发现问题就是出在devexpress的gridcontrol绑定上,取数据前先要清除gridcontrol的数据绑定,再取数据并重新绑定。