未将对象引用设置到对象的实例 查询出数据了  但是不能和标题对应用了标题对应的列名在标题那一行继续排列        private void but_c1_Click(object sender, EventArgs e)
            {
            string Gyw = this.txt_c1.Text.ToString().Trim();
                if (op.Gettel(Gyw))
                {
                    MessageBox.Show("查询记录成功!", "温馨提示");
                    
                    
                    this.dataGridView1.DataSource = ds.Tables[0];
                    bindDataGridView();
                    }
                else
                    {                    MessageBox.Show("查询记录失败!", "温馨提示");
                    clear();
                    bindDataGridView();
                    }     
            }

解决方案 »

  1.   

    有关调用实时(JIT)调试而不是此对话框的详细信息,
    请参见此消息的结尾。************** 异常文本 **************
    System.NullReferenceException: 未将对象引用设置到对象的实例。
       在 teleOrder.User.dataGridView1_RowEnter(Object sender, DataGridViewCellEventArgs e) 位置 D:\我的文档\My Documents\Visual Studio 2008\Projects\teleOrder\teleOrder\User.cs:行号 213
       在 System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCellEventArgs e)
       在 System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
       在 System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
       在 System.Windows.Forms.DataGridView.SetAndSelectCurrentCellAddress(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick, Boolean clearSelection, Boolean forceCurrentCellSelection)
       在 System.Windows.Forms.DataGridView.MakeFirstDisplayedCellCurrentCell(Boolean includeNewRow)
       在 System.Windows.Forms.DataGridView.OnRowCollectionChanged_PostNotification(Boolean recreateNewRow, Boolean allowSettingCurrentCell, CollectionChangeAction cca, DataGridViewRow dataGridViewRow, Int32 rowIndex)
       在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow dataGridViewRow, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
       在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
       在 System.Windows.Forms.DataGridViewRowCollection.InsertInternal(Int32 rowIndex, DataGridViewRow dataGridViewRow, Boolean force)
       在 System.Windows.Forms.DataGridViewRowCollection.InsertInternal(Int32 rowIndex, DataGridViewRow dataGridViewRow)
       在 System.Windows.Forms.DataGridViewRowCollection.AddInternal(DataGridViewRow dataGridViewRow)
       在 System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView)
       在 System.Windows.Forms.DataGridView.RefreshColumnsAndRows()
       在 System.Windows.Forms.DataGridView.OnBindingContextChanged(EventArgs e)
       在 System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
       在 System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
       在 System.Windows.Forms.Control.set_BindingContextInternal(BindingContext value)
       在 System.Windows.Forms.ContainerControl.set_BindingContext(BindingContext value)
       在 System.Windows.Forms.ContainerControl.get_BindingContext()
       在 System.Windows.Forms.Control.get_BindingContextInternal()
       在 System.Windows.Forms.Control.get_BindingContext()
       在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.SetDataConnection(Object dataSource, String dataMember)
       在 System.Windows.Forms.DataGridView.set_DataSource(Object value)
       在 teleOrder.User.but_c1_Click(Object sender, EventArgs e) 位置 D:\我的文档\My Documents\Visual Studio 2008\Projects\teleOrder\teleOrder\User.cs:行号 280
       在 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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    ************** 已加载的程序集 **************
    mscorlib
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    teleOrder
        程序集版本: 1.0.0.0
        Win32 版本: 1.0.0.0
        基本代码: file:///D:/我的文档/My%20Documents/Visual%20Studio%202008/Projects/teleOrder/teleOrder/bin/Release/teleOrder.exe
    ----------------------------------------
    System.Windows.Forms
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Drawing
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System.Data
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
    ----------------------------------------
    System.Xml
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    System.Windows.Forms.resources
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dll
    ----------------------------------------
    System.Configuration
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Transactions
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
    ----------------------------------------
    System.EnterpriseServices
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
    ----------------------------------------
    mscorlib.resources
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
        基本代码: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------************** JIT 调试 **************
    要启用实时(JIT)调试,
    该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
    jitDebugging 值。
    编译应用程序时还必须启用
    调试。例如: <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>启用 JIT 调试后,任何无法处理的异常
    都将被发送到在此计算机上注册的 JIT 调试器,
    而不是由此对话框处理。
      

  2.   

                public bool Gettel(string Gyw)
                    {
                    string sql = "select * from work where Gyw='"+Gyw+"'";
                    //SqlConnection conn = new SqlConnection("Persist Security Info=true;Integrated Security=SSPI;database=longj;server=.;Connect Timeout=30");
                    DataSet ds = new DataSet();
                    SqlDataAdapter sda = new SqlDataAdapter(sql, conn);                try
                        {
                        if (conn.State != ConnectionState.Open)
                            conn.Open();
                        sda.Fill(ds);
                        return ds.Tables[0].Rows.Count > 0;
                        }
                    catch (Exception ex)
                        {
                        throw ex;
                        }
                    finally
                        {
                        conn.Close();
                        }
                    }
      

  3.   

    出错方法的第213行.
    teleOrder.User.dataGridView1_RowEnter(Object sender, DataGridViewCellEventArgs e)第213行是什么?试试:
    private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
    {
        if (dataGridView1.CurrentCell == null) return;
        if (e.RowIndex < 0 || e.ColumnIndex < 0) return;    // ...你原来的代码
    }
      

  4.   

    namespace teleOrder
        {
        public partial class User : Form
            {
            public gyk op;
            public DataSet ds;
            UserInfoOBJ userinfoobj;
            public User()
                {
                InitializeComponent();
                op = new gyk();
                ds = new DataSet();
                userinfoobj = new UserInfoOBJ();
                }
            public void bindDataGridView()
                {
                ds = op.GetUserInfo();
                this.dataGridView1.Rows.Clear();
                          
                if (ds.Tables[0].Rows.Count > 0)
                    {                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                        string[] data = new string[] { ds.Tables[0].Rows[i][0].ToString(), ds.Tables[0].Rows[i][1].ToString(), ds.Tables[0].Rows[i][2].ToString(), ds.Tables[0].Rows[i][3].ToString(), ds.Tables[0].Rows[i][4].ToString(), ds.Tables[0].Rows[i][5].ToString(), ds.Tables[0].Rows[i][6].ToString(), ds.Tables[0].Rows[i][7].ToString(), ds.Tables[0].Rows[i][8].ToString(), ds.Tables[0].Rows[i][9].ToString(), ds.Tables[0].Rows[i][10].ToString(), ds.Tables[0].Rows[i][11].ToString(), ds.Tables[0].Rows[i][12].ToString(), ds.Tables[0].Rows[i][13].ToString()};
                        this.dataGridView1.Rows.Add(data);                    }
                    }            }        public void User_Load(object sender, EventArgs e)
                {
                bindDataGridView();
                }        public void label1_Click(object sender, EventArgs e)
                {            }        public void label1_Click_1(object sender, EventArgs e)
                {            }              private void dataGridView1_Click_1(object sender, EventArgs e)
                {
                if (this.dataGridView1.SelectedRows.Count > 0)
                    {       
                    this.lab_uid.Text = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    this.txt_gongdan.Text = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    this.txt_time.Text = this.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                    this.txt_ad.Text = this.dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                    this.txt_zl.Text = this.dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
                    this.txt_zh.Text = this.dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
                    this.txt_pw.Text = this.dataGridView1.SelectedRows[0].Cells[6].Value.ToString();
                    this.txt_yw.Text = this.dataGridView1.SelectedRows[0].Cells[7].Value.ToString();
                    this.txt_lianxi.Text = this.dataGridView1.SelectedRows[0].Cells[8].Value.ToString();
                    this.txt_jf.Text = this.dataGridView1.SelectedRows[0].Cells[9].Value.ToString();
                    this.txt_l.Text = this.dataGridView1.SelectedRows[0].Cells[10].Value.ToString();
                    this.txt_p.Text = this.dataGridView1.SelectedRows[0].Cells[11].Value.ToString();
                    this.txt_h.Text = this.dataGridView1.SelectedRows[0].Cells[12].Value.ToString();
                    this.txt_v.Text = this.dataGridView1.SelectedRows[0].Cells[13].Value.ToString();
                    } 
                }        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
                {            }        private void btn_add_Click(object sender, EventArgs e)
                {
                userinfoobj.Gid = this.lab_uid.Text.Trim();
                userinfoobj.GOrder = this.txt_gongdan.Text.Trim();
                userinfoobj.Gtime = this.txt_time.Text.Trim();
                userinfoobj.Gadress = this.txt_ad.Text.Trim();
                userinfoobj.Gzl = this.txt_zl.Text.Trim();
                userinfoobj.Gzh = this.txt_zh.Text.Trim();
                userinfoobj.Gpw = this.txt_pw.Text.Trim();
                userinfoobj.Gyw = this.txt_yw.Text.Trim();
                userinfoobj.Glianxi = this.txt_lianxi.Text.Trim();
                userinfoobj.Jf = this.txt_jf.Text.Trim();
                userinfoobj.L = this.txt_l.Text.Trim();
                userinfoobj.P = this.txt_p.Text.Trim();
                userinfoobj.H = this.txt_h.Text.Trim();
                userinfoobj.V = this.txt_v.Text.Trim();
               
                
                
                //if (this.lbl_userId.Text.Trim() == "")//如果等于空--》新添记录    否则为编辑 状态
                //    {
                if (op.AddUser(userinfoobj))
                    {
                    MessageBox.Show("成功添加记录!","温馨提示");
                    bindDataGridView();
                    }
                else
                    {                MessageBox.Show("添加记录失败!", "温馨提示");
                    bindDataGridView();
                    }
                }        private void btn_edt_Click(object sender, EventArgs e)
                {
                userinfoobj.Gid = this.lab_uid.Text.Trim();
                userinfoobj.GOrder = this.txt_gongdan.Text.Trim();
                userinfoobj.Gtime = this.txt_time.Text.Trim();
                userinfoobj.Gadress = this.txt_ad.Text.Trim();
                userinfoobj.Gzl = this.txt_zl.Text.Trim();
                userinfoobj.Gzh = this.txt_zh.Text.Trim();
                userinfoobj.Gpw = this.txt_pw.Text.Trim();
                userinfoobj.Gyw = this.txt_yw.Text.Trim();
                userinfoobj.Glianxi = this.txt_lianxi.Text.Trim();
                userinfoobj.Jf = this.txt_jf.Text.Trim();
                userinfoobj.L = this.txt_l.Text.Trim();
                userinfoobj.P = this.txt_p.Text.Trim();
                userinfoobj.H = this.txt_h.Text.Trim();
                userinfoobj.V = this.txt_v.Text.Trim();
                if (this.lab_uid.Text.Trim() == "")//如果等于空--》新添记录    否则为编辑 状态
                    {
                    MessageBox.Show("请输入数值!", "提示");
                    }
                else
                    {                if (op.EditUserInfo(userinfoobj))
                        {
                        MessageBox.Show("修改记录成功!", "提示");
                        bindDataGridView();
                        }
                    else
                        {                    MessageBox.Show("修改记录失败!", "很遗憾");
                        bindDataGridView();
                        }
                    }
                }        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
                {            }        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
                {            //if (dataGridView1.CurrentCell == null) return;
                //if (e.RowIndex < 0 || e.ColumnIndex < 0) return;             this.lab_uid.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                 this.txt_gongdan.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                 this.txt_time.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); ;
                 this.txt_ad.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                 this.txt_zl.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
                 this.txt_zh.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
                 this.txt_pw.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
                 this.txt_yw.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
                 this.txt_lianxi.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
                 this.txt_jf.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString();
                 this.txt_l.Text = dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString();
                 this.txt_p.Text = dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString();
                 this.txt_h.Text = dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString();
                 this.txt_v.Text = dataGridView1.Rows[e.RowIndex].Cells[13].Value.ToString();
                }        public void clear()
                {            this.lab_uid.Text = "";
                this.txt_gongdan.Text = "";
                this.txt_time.Text = "";
                this.txt_ad.Text = "";
                this.txt_zl.Text = "";
                this.txt_zh.Text = "";
                this.txt_pw.Text = "";
                this.txt_yw.Text = "";
                this.txt_lianxi.Text = "";
                this.txt_jf.Text = "";
                this.txt_l.Text = "";
                this.txt_p.Text = "";
                this.txt_h.Text = "";
                this.txt_v.Text = "";
                }
            private void but_del_Click(object sender, EventArgs e)
                {
                string Gid = lab_uid.Text.Trim();
                if (op.DeleteUserInfo(Gid))
                    {
                    MessageBox.Show("删除记录成功!","恭喜您");
                    clear();
                    bindDataGridView();
                    }
                else
                    {                MessageBox.Show("删除记录失败!", "很遗憾");
                    clear();
                    bindDataGridView();
                    }
                }        private void but_qingkong_Click(object sender, EventArgs e)
                {
                    clear();
                    MessageBox.Show("清理成功", "恭喜您");
                }        private void but_c1_Click(object sender, EventArgs e)
                {            string Gyw = this.txt_c1.Text.ToString().Trim();
                    if (op.Gettel(Gyw))
                    {
                    MessageBox.Show("查询记录成功!", "恭喜您");
                        
                        
                        this.dataGridView1.DataSource = ds.Tables[0];
                        bindDataGridView();
                        }
                    else
                        {                    MessageBox.Show("查询记录失败!", "很遗憾");
                        clear();
                        bindDataGridView();
                        }     
                }
            }
        }
      

  5.   

    未处理 System.NullReferenceException
      Message="未将对象引用设置到对象的实例。"
      Source="teleOrder"
      StackTrace:
           在 teleOrder.User.dataGridView1_RowEnter(Object sender, DataGridViewCellEventArgs e) 位置 D:\我的文档\My Documents\Visual Studio 2008\Projects\teleOrder\teleOrder\User.cs:行号 217
           在 System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCellEventArgs e)
           在 System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
           在 System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
           在 System.Windows.Forms.DataGridView.SetAndSelectCurrentCellAddress(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick, Boolean clearSelection, Boolean forceCurrentCellSelection)
           在 System.Windows.Forms.DataGridView.MakeFirstDisplayedCellCurrentCell(Boolean includeNewRow)
           在 System.Windows.Forms.DataGridView.OnRowCollectionChanged_PostNotification(Boolean recreateNewRow, Boolean allowSettingCurrentCell, CollectionChangeAction cca, DataGridViewRow dataGridViewRow, Int32 rowIndex)
           在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow dataGridViewRow, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
           在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
           在 System.Windows.Forms.DataGridViewRowCollection.InsertInternal(Int32 rowIndex, DataGridViewRow dataGridViewRow, Boolean force)
           在 System.Windows.Forms.DataGridViewRowCollection.InsertInternal(Int32 rowIndex, DataGridViewRow dataGridViewRow)
           在 System.Windows.Forms.DataGridViewRowCollection.AddInternal(DataGridViewRow dataGridViewRow)
           在 System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView)
           在 System.Windows.Forms.DataGridView.RefreshColumnsAndRows()
           在 System.Windows.Forms.DataGridView.OnBindingContextChanged(EventArgs e)
           在 System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
           在 System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
           在 System.Windows.Forms.Control.set_BindingContextInternal(BindingContext value)
           在 System.Windows.Forms.ContainerControl.set_BindingContext(BindingContext value)
           在 System.Windows.Forms.ContainerControl.get_BindingContext()
           在 System.Windows.Forms.Control.get_BindingContextInternal()
           在 System.Windows.Forms.Control.get_BindingContext()
           在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.SetDataConnection(Object dataSource, String dataMember)
           在 System.Windows.Forms.DataGridView.set_DataSource(Object value)
           在 teleOrder.User.but_c1_Click(Object sender, EventArgs e) 位置 D:\我的文档\My Documents\Visual Studio 2008\Projects\teleOrder\teleOrder\User.cs:行号 284
           在 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.Application.Run(Form mainForm)
           在 teleOrder.Program.Main() 位置 D:\我的文档\My Documents\Visual Studio 2008\Projects\teleOrder\teleOrder\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: 
      

  6.   

    这里有问题···
    我的意思是返回一行并且和标题对得上
            private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
                {            //if (dataGridView1.CurrentCell == null) return;
                //if (e.RowIndex < 0 || e.ColumnIndex < 0) return;             this.lab_uid.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                 this.txt_gongdan.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                 this.txt_time.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); ;
                 this.txt_ad.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                 this.txt_zl.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
                 this.txt_zh.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
                 this.txt_pw.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
                 this.txt_yw.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
                 this.txt_lianxi.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
                 this.txt_jf.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString();
                 this.txt_l.Text = dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString();
                 this.txt_p.Text = dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString();
                 this.txt_h.Text = dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString();
                 this.txt_v.Text = dataGridView1.Rows[e.RowIndex].Cells[13].Value.ToString();
                }
      

  7.   

    dataGridView1_RowEnter提示的很清楚这个函数出了问题
    看你这个函数里面引用了不少列,是不是超了了列的索引范围?
      

  8.   


    你那么多的tostring()
    是不是数据库取出来有Null然后tostring了?
    null的tostring肯定报空引用错~
      

  9.   

    改一下,找到出错原因,你自己就知道怎么解决了。private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
    {
        try
        {
            this.lab_uid.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
            this.txt_gongdan.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
            this.txt_time.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); ;
            this.txt_ad.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
            this.txt_zl.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
            this.txt_zh.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
            this.txt_pw.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
            this.txt_yw.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
            this.txt_lianxi.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
            this.txt_jf.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString();
            this.txt_l.Text = dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString();
            this.txt_p.Text = dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString();
            this.txt_h.Text = dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString();
            this.txt_v.Text = dataGridView1.Rows[e.RowIndex].Cells[13].Value.ToString();
        }
        catch (Exception ex) { MessageBox.Show(ex.ToString()); }
    }
      

  10.   


    //试一下 我自己也不知道对不
       string Dym = this.txt_c1.Text.ToString().Trim();


    string sql = "select * from work where Gyw='"+Gyw+"'"; 
    list li = new List();
    sqlcommand cmd = new  sqlcommand (sql.conn);
    sqlDataReader dr = cmd.ExcutReader();
    which(dr.read())
    {
    //将实体添加到list
    li.add(......);
    }

    this.dataGridView1.DataSource = li;
    dataGridView1.DataBing();