首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

未将对象引用设置到对象的实例解决方案

2012-03-01 
未将对象引用设置到对象的实例privatevoidReturnUserData(intiRet){stringstrSQL LinkDataBaselinkne

未将对象引用设置到对象的实例
private   void   ReturnUserData(int   iRet)
                {
                        string   strSQL   =   " ";
                        LinkDataBase   link   =   new   LinkDataBase();
                        DataSet   ds   =   new   DataSet();
                        DataTable   dt;
                        if   (iRet   !=   0)
                        {
                                strSQL   =   "select   *   from   SysUser   where   SysUserID   =   ' "   +   iRet   +   " ' ";
                        }
                        ds   =   link.SelectDB(strSQL);
                        if   (ds.Tables[0].Rows.Count   >   0)
                        {
                                dt   =   ds.Tables[0];
                                this.textBox1.Text   =   dt.Rows[0][ "SysUserCode "].ToString();
                                this.textBox2.Text   =   dt.Rows[0][ "SysUserName "].ToString();
                                this.textBox3.Text   =   dt.Rows[0][ "Psw "].ToString();
                                this.textBox4.Text   =   dt.Rows[0][ "Email "].ToString();
                                this.textBox5.Text   =   dt.Rows[0][ "Tel "].ToString();
                                this.textBox6.Text   =   dt.Rows[0][ "Address "].ToString();
                                this.comboBox1.Text   =   dt.Rows[0][ "DeptID "].ToString();
                                this.comboBox2.Text   =   dt.Rows[0][ "Sex "].ToString();
                        }
                }

为什么老是在运行到this.textBox1.Text   =   dt.Rows[0][ "SysUserCode "].ToString();就出现“未将对象引用设置到对象的实例”啊,请帮帮,急呀!

------解决方案--------------------


这么说吧,我现在就是要把数据库里读出的一些数据,显示在那些文本框和下拉框里,还有没有别的方法。因为我要对那些用户进行修改,所以是必须显示在窗体上的。
==============
这些没问题可以做到,主要是你要看看你该完代码后 控件生成的代码是否有误,例如你的控件没有添加到form的controls中

热点排行