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

提醒小弟我确保列表索引的最大索引小于列表的大小,

2012-05-16 
提醒我确保列表索引的最大索引小于列表的大小,求助!!!!!!!protected void Page_Load(object sender, Event

提醒我确保列表索引的最大索引小于列表的大小,求助!!!!!!!
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]["标志图标"];                } 

热点排行