单击按钮时出现错误*对象参考未设置为对象的距离* [英] got an error when click on button *object refrence not set to an istance of object*

查看:73
本文介绍了单击按钮时出现错误*对象参考未设置为对象的距离*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void Account_Search_Load(object sender, EventArgs e)
       {
           if (cn.State == ConnectionState.Open)
           {
               cn.Close();
           }
           else
           {
               cn.Open();

               String query = "Select * from Accounts";
               da = new SqlDataAdapter(query, cn);
               dt = new DataTable();
               da.Fill(dt);

           }




private void btnlast_Click(object sender, EventArgs e)
      {
          r = dt.Rows.Count - 1;
          displayrecord();
      }
      private void displayrecord()
      {
           txtcity.Text = dt.Rows[r]["City"].ToString();
                       txtdistrict.Text = dt.Rows[r]["District"].ToString();
                       txtfather1.Text = dt.Rows[r]["Father_name"].ToString();
                       txthusband1.Text = dt.Rows[r]["Husband_name"].ToString();
                       txtinitial.Text = dt.Rows[r]["Initial_Deposite"].ToString();
                       txtmarital.Text = dt.Rows[r]["Marital_Status"].ToString();
                       txtname1.Text = dt.Rows[r]["Name"].ToString();
                       txtnature.Text = dt.Rows[r]["Account_Nature"].ToString();
                       txtoccupation1.Text = dt.Rows[r]["Occupation"].ToString();
                       txtpostal.Text = dt.Rows[r]["Postal_Code"].ToString();
                       txttype.Text = dt.Rows[r]["Account_type"].ToString();
                       dateTimePicker1.Value = Convert.ToDateTime(dt.Rows[r]["Entry_Date"]);
                       txtaccounttitle.Text = dt.Rows[r]["Account_title"].ToString();

                      string str;
                      str = dt.Rows[r]["Account_No"].ToString();
                      string[] account;
                      account = str.Split('-');
                       txtaccount1.Text = account[0];
                       txtaccount2.Text = account[1];

                      string str1;
                      str1 = dt.Rows[r]["Mobile"].ToString();
                      string[] Mobile;
                      Mobile = str1.Split('-');
                       txtcode.Text = Mobile[0];
                       txtmobile1.Text = Mobile[1];



                      if (dt.Rows[r]["Gender"].ToString() == "Male")
                      {
                           rdomale.Checked = true;
                      }
                      else
                      {
                           rdofemale.Checked = true;


                      }

                                         }
              }

推荐答案

该错误意味着您的DataTable没有任何数据。一旦检查出你的代码,我们会给你一个断点并结账。数据表是否有数据。
That error meaning is your DataTable don''t have a any data. once check out your code putting a break point and checkout . whether your datatable have a data or not.


这篇关于单击按钮时出现错误*对象参考未设置为对象的距离*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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