这是cs代码using System;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Xml.Linq;
public partial class zizhutingcheaspx : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
     
  }
   protected void Button1_Click(object sender, EventArgs e)
   {
     
    
    
  string strConn;
   SqlDataAdapter objDataAdapter;
   strConn = "server=localhost;database=intelliCampus;uid=sa;pwd=123"; //不区分大小写,ok //值为true(同sspi),OK
   SqlConnection myConn = new SqlConnection(strConn);
   myConn.Open();
   SqlCommand cmd = new SqlCommand("select * from tb_sensor_parkingPlace", myConn);
   objDataAdapter = new System.Data.SqlClient.SqlDataAdapter("SELECT [status] FROM [tb_sensor_parkingPlace]", myConn);
   DataTable dt = new DataTable();
   objDataAdapter.Fill(dt);
   int[] a = new int[27];
   for (int i = 0; i <= 27; i++)//这有时也提示越界错误
   {
   a[i] = int.Parse(dt.Rows[i].ToString());//这提示formatexeceptionhe
错误 功能是从数据库的一个表中取出某一列赋给一个数组}
     
  for (int j = 0; j < 27; j++)
   {
   int n = j + 13;   if (a[j] == 0)
   {
     
  FindControl("apDiv" + n.ToString()).Visible = false;//隐藏     }
   else  
  {
   FindControl("apDiv" + n.ToString()).Visible = true;//显示
   }
   }     
  myConn.Close();//关闭数据库的连接
   myConn = null;   }
}

解决方案 »

  1.   

    a[i] = int.Parse(dt.Rows[i].ToString());//这提示formatexeceptionhe
    红色部分可能是空串或者不能转化为数字的字符
      

  2.   

    int[] a = new int[27];
    for (int i = 0; i <= 27; i++)//这有时也提示越界错误你都不知道DataTable里面总共有多少条记录,如果比28条少的话,肯定会越界了
    int[] a = new int[dt.Rows.Count];
    for (int i = 0; i < dt.Rows.Count; i++)
      

  3.   

    formatexeceptionhe格式化错误,就是不能转换为int类型。数组a的长度是27,而你的循环语句是<=27,当i=27的时候就数组越界了,因为你访问的是第28个数字。应该是i<27
      

  4.   

    重点是红色部分。int[] a = new int[27];
    for (int i = 0; i <= 27; i++)//这有时也提示越界错误
    {
    a[i] = int.Parse(dt.Rows[i].ToString());//这提示formatexeceptionhe
      

  5.   

    int.Parse()可以尝试用int.TryParse()函数。
      

  6.   


      for (int i = 0; i <= 27; i++)//这有时也提示越界错误
      {
      a[i] = int.Parse(dt.Rows[i].ToString());//这提示formatexeceptionhe
    错误 功能是从数据库的一个表中取出某一列赋给一个数组}你是有声明一个27行的数组,你是,别忘了程序是0开始索引。
    也就说,是有27行,但程序只读到26.改成这样吧  for (int i = 0; i < 27; i++)//去掉等号
      {
      a[i] = int.Parse(dt.Rows[i]);}
      

  7.   

    int[] a = new int[27];
    有27条数据 你取出来 这个应该是可变的a[i] = int.Parse(dt.Rows[i]["列名"].ToString());
    你断点看你取出来的数据时什么格式 能进行转换按吗?
      

  8.   

    1.你的command用来干什么的 - -2.数组不是n[27] 么  最大索引就26 你还<=27!3 a[i] = int.Parse(dt.Rows[i].ToString());//这提示formatexeceptionhe
    错误 功能是从数据库的一个表中取出某一列赋给一个数组}指定行没有指定列啊 dt.Rows[i]["列名"] 或dt.Rows[i]["索引"]