日期:2014-05-18  浏览次数:21025 次

提醒我确保列表索引的最大索引小于列表的大小,求助!!!!!!!
protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  this.Page.Title = "当前位置:系统首页";
  string MyConnectionString = ConfigurationManager.ConnectionStrings["MyPersonnelDBConnectionString"].ConnectionString;
  string MySQL = "Select * From 公司信息 Where 优先级=1";
  SqlConnection MyConnection = new SqlConnection(MyConnectionString);
  MyConnection.Open();
  DataTable MyTable = new DataTable();
  SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
  MyAdapter.Fill(MyTable);
  这段//this.Image1.ImageUrl = "~/Images/" + (String)MyTable.Rows[0]["首页图像"];
  Session["MySystemName"] = (String)MyTable.Rows[0]["系统名称"];
  Session["MyCompanyWebSite"] = (String)MyTable.Rows[0]["公司网站"].ToString();
  Session["MyCompanyName"] = (String)MyTable.Rows[0]["公司名称"];
  Session["MyCompanyAddress"] = (String)MyTable.Rows[0]["公司地址"];
  Session["MyCompanyPhone"] = (String)MyTable.Rows[0]["服务电话"];
  Session["MyCompanyLogo"] = (String)MyTable.Rows[0]["标志图标"];
  if (MyConnection.State == ConnectionState.Open)
  {
  MyConnection.Close();
  }
  }
  }
}

------解决方案--------------------
C# code

 if (MyTable.Rows.Count > 0)
                {
                      this.Image1.ImageUrl = "~/Images/" + (String)MyTable.Rows[0]["首页图像"];
                      Session["MySystemName"] = (String)MyTable.Rows[0]["系统名称"];
                      Session["MyCompanyWebSite"] = (String)MyTable.Rows[0]["公司网站"].ToString();
                      Session["MyCompanyName"] = (String)MyTable.Rows[0]["公司名称"];
                      Session["MyCompanyAddress"] = (String)MyTable.Rows[0]["公司地址"];
                      Session["MyCompanyPhone"] = (String)MyTable.Rows[0]["服务电话"];
                      Session["MyCompanyLogo"] = (String)MyTable.Rows[0]["标志图标"];

                }