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

提醒我确保列表索引的最大索引小于列表的大小,但是不知道具体该怎么解决
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();
  }
  }
  }
}

------解决方案--------------------
你确认 MyTable.Rows 肯定有Row吗,最好写个if语句判断一下吧
------解决方案--------------------
你获取的是哪一行的那一列的值,你看看你报错的(String)MyTable.Rows[0]["首页图像"]这个得到什么值