未处理 System.IndexOutOfRangeException
  Message="无法找到表 0。"
  Source="System.Data"
  StackTrace:
       在 System.Data.DataTableCollection.get_Item(Int32 index)
       在 自己做的登陆系统.SearchForm.button1_Click(Object sender, EventArgs e) 位置 H:\通讯录登陆系统\自己做的登陆系统\自己做的登陆系统\SearchForm.cs:行号 46
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.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.Form.ShowDialog(IWin32Window owner)
       在 System.Windows.Forms.Form.ShowDialog()
       在 自己做的登陆系统.AdminFrom.Search() 位置 H:\通讯录登陆系统\自己做的登陆系统\自己做的登陆系统\AdminFrom.cs:行号 244
       在 自己做的登陆系统.AdminFrom.toolStripButton4_Click(Object sender, EventArgs e) 位置 H:\通讯录登陆系统\自己做的登陆系统\自己做的登陆系统\AdminFrom.cs:行号 239
       在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
       在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
       在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
       在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
       在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
       在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
       在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       在 System.Windows.Forms.ToolStrip.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)
       在 自己做的登陆系统.Program.Main() 位置 H:\通讯录登陆系统\自己做的登陆系统\自己做的登陆系统\Program.cs:行号 18
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

解决方案 »

  1.   

    你的存储过程没有返回任何数据集,直接查询分析器执行下该存储过程试试多余的select语句也会造成这个问题
      

  2.   

    后面两个If 的条件是重复的:len(@name)=0 and len(@phone)<>0如果你传入的参数@user为空不会返回数据集。
    如果你传入的参数@name和@phone都不为空也不会返回数据集。你查一下传给存储过程的是什么样的参数。
      

  3.   

    按你的意思最后的If的条件应该是这个吧:len(@name)<>0 and len(@phone)<>0