| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3376 人关注过本帖
标题:关于SqlParameter[] 索引超出了数组界限
只看楼主 加入收藏
tokoyoshi
Rank: 2
等 级:论坛游民
帖 子:99
专家分:67
注 册:2009-10-24
结帖率:87.1%
收藏
已结贴  问题点数:20 回复次数:6 
关于SqlParameter[] 索引超出了数组界限
索引超出了数组界限。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.IndexOutOfRangeException: 索引超出了数组界限。

源错误:


行 222:            parameters[89].Value = model.Pic;
行 223:            parameters[90].Value = model.PContent;
行 224:            parameters[91].Value = model.Sort;
行 225:            parameters[92].Value = model.CTR;
行 226:
 

源文件: C:\Auto最新\Auto\Auto.SQLServerDAL\AutoProductService.cs    行: 224





代码:
    /// <summary>
        /// 增加一条数据
        /// </summary>
        public static int Add(AutoProduct model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into AutoProduct(");
            strSql.Append("[ProductId],[CategorieId],[ModelId],[Title],[Pic],[chekuanming],[zhidaojiage],[chandi],[chicun],[zhouju],[zuidagonglv],[zuidaniuju],[biansuqi],[zuigaochesu],[ranyou],[zongheyouhao],[zhengbeizhiliang],[zuowei],[xinglixiangrongji],[chemen],[qianlunju],[houlunju],[zuixiaolidijianxi],[qianxuangua],[houxuangua],[qianhouzhidongqileixing],[qudongfangshi],[tianchuang],[cheshenyanse],[lvhejinlungu],[paiqiliang],[yasuobi],[qigangxingshi],[fadongjichangjiaxinghao],[jiasushijian],[qianhouluntaiguige],[fengzuxishu],[anquanqinang],[ABS],[zhidonglifenpei],[qianyinlikongzhi],[taiyajiancezhuangzhi],[lingtaiyajixuxingshi],[donglisuisuzhuanxiang],[zhudongzhuanxiangxitong],[fangxiangpan],[zuojiaoxiuxitaban],[fangxiangpantiaojie],[duogongnengfangxiangpan],[dingsuxunhang],[bochefuzhu],[duogongnengxianshiping],[zuoyi],[zuoyitiaojie],[yaobuzhichengtiaojie],[qianpaizuoyidiandongtiaojie],[zuoyijiare],[qianzuozhongyangfushou],[houzuozhongyangfushou],[houpaizuoyianbilifangdao],[yinxiangxitong],[yangshengqigeshu],[GPSdaohangxitong],[duomeitikongzhixitong],[chezaidianhua],[zhongkongtaiyejingping],[houpaiyejingping],[MP3zhichi],[dadeng],[wudeng],[qiandiandongchechuang],[houdiandongchechuang],[fangjiashougongneng],[diandonghoushijing],[houshijingjiare],[houshijingdiandongzhedie],[zheyanglian],[houshijingfangxuanmu],[zheyangbanhuazhuangjing],[ganyingyushua],[kongtiao],[chufengkou],[cheneikongqitiaojie],[chezaibingxiang],[dianzifangdao],[cheneizhongkongsuo],[yaokongyaoshi],[wuyaoshiqidongxitong],[PContent],[Sort],[CTR])");
            strSql.Append(" values (");
            strSql.Append("@ProductId,@CategorieId,@ModelId,@title,@pic,@chekuanming,@zhidaojiage,@chandi,@chicun,@zhouju,@zuidagonglv,@zuidaniuju,@biansuqi,@zuigaochesu,@ranyou,@zongheyouhao,@zhengbeizhiliang,@zuowei,@xinglixiangrongji,@chemen,@qianlunju,@houlunju,@zuixiaolidijianxi,@qianxuangua,@houxuangua,@qianhouzhidongqileixing,@qudongfangshi,@tianchuang,@cheshenyanse,@lvhejinlungu,@paiqiliang,@yasuobi,@qigangxingshi,@fadongjichangjiaxinghao,@jiasushijian,@qianhouluntaiguige,@fengzuxishu,@anquanqinang,@ABS,@zhidonglifenpei,@qianyinlikongzhi,@taiyajiancezhuangzhi,@lingtaiyajixuxingshi,@donglisuisuzhuanxiang,@zhudongzhuanxiangxitong,@fangxiangpan,@zuojiaoxiuxitaban,@fangxiangpantiaojie,@duogongnengfangxiangpan,@dingsuxunhang,@bochefuzhu,@duogongnengxianshiping,@zuoyi,@zuoyitiaojie,@yaobuzhichengtiaojie,@qianpaizuoyidiandongtiaojie,@zuoyijiare,@qianzuozhongyangfushou,@houzuozhongyangfushou,@houpaizuoyianbilifangdao,@yinxiangxitong,@yangshengqigeshu,@GPSdaohangxitong,@duomeitikongzhixitong,@chezaidianhua,@zhongkongtaiyejingping,@houpaiyejingping,@MP3zhichi,@dadeng,@wudeng,@qiandiandongchechuang,@houdiandongchechuang,@fangjiashougongneng,@diandonghoushijing,@houshijingjiare,@houshijingdiandongzhedie,@zheyanglian,@houshijingfangxuanmu,@zheyangbanhuazhuangjing,@ganyingyushua,@kongtiao,@chufengkou,@cheneikongqitiaojie,@chezaibingxiang,@dianzifangdao,@cheneizhongkongsuo,@yaokongyaoshi,@wuyaoshiqidongxitong,@pContent,@sort,@CTR)");
            SqlParameter[] parameters =new SqlParameter[] {
         new SqlParameter("@ProductId", SqlDbType.Int,4),
         new SqlParameter("@CategorieId", SqlDbType.Int,4),
         new SqlParameter("@ModelId", SqlDbType.Int,4),
         new SqlParameter("@chekuanming", SqlDbType.NVarChar,50),
         new SqlParameter("@zhidaojiage", SqlDbType.Money,8),
         new SqlParameter("@chandi", SqlDbType.NChar,10),
         new SqlParameter("@chicun", SqlDbType.NVarChar,50),
         new SqlParameter("@zhouju", SqlDbType.NVarChar,50),
         new SqlParameter("@zuidagonglv", SqlDbType.NVarChar,50),
         new SqlParameter("@zuidaniuju", SqlDbType.NVarChar,50),
         new SqlParameter("@biansuqi", SqlDbType.NVarChar,50),
         new SqlParameter("@zuigaochesu", SqlDbType.NVarChar,50),
         new SqlParameter("@ranyou", SqlDbType.NVarChar,50),
         new SqlParameter("@zongheyouhao", SqlDbType.NVarChar,50),
         new SqlParameter("@zhengbeizhiliang", SqlDbType.NVarChar,50),
         new SqlParameter("@zuowei", SqlDbType.NVarChar,50),
         new SqlParameter("@xinglixiangrongji", SqlDbType.NVarChar,50),
         new SqlParameter("@chemen", SqlDbType.NVarChar,50),
         new SqlParameter("@qianlunju", SqlDbType.NVarChar,50),
         new SqlParameter("@houlunju", SqlDbType.NVarChar,50),
         new SqlParameter("@zuixiaolidijianxi", SqlDbType.NVarChar,50),
         new SqlParameter("@qianxuangua", SqlDbType.NVarChar,100),
         new SqlParameter("@houxuangua", SqlDbType.NVarChar,100),
         new SqlParameter("@qianhouzhidongqileixing", SqlDbType.NVarChar,100),
         new SqlParameter("@qudongfangshi", SqlDbType.NVarChar,50),
         new SqlParameter("@tianchuang", SqlDbType.NVarChar,50),
         new SqlParameter("@cheshenyanse", SqlDbType.NVarChar,50),
         new SqlParameter("@lvhejinlungu", SqlDbType.NVarChar,50),
         new SqlParameter("@paiqiliang", SqlDbType.NVarChar,50),
         new SqlParameter("@yasuobi", SqlDbType.NVarChar,50),
         new SqlParameter("@qigangxingshi", SqlDbType.NVarChar,50),
         new SqlParameter("@fadongjichangjiaxinghao", SqlDbType.NVarChar,50),
         new SqlParameter("@jiasushijian", SqlDbType.NVarChar,50),
         new SqlParameter("@qianhouluntaiguige", SqlDbType.NVarChar,50),
         new SqlParameter("@fengzuxishu", SqlDbType.NVarChar,50),
         new SqlParameter("@anquanqinang", SqlDbType.NVarChar,50),
         new SqlParameter("@ABS", SqlDbType.NVarChar,50),
         new SqlParameter("@zhidonglifenpei", SqlDbType.NVarChar,50),
         new SqlParameter("@qianyinlikongzhi", SqlDbType.NVarChar,50),
         new SqlParameter("@taiyajiancezhuangzhi", SqlDbType.NVarChar,50),
         new SqlParameter("@lingtaiyajixuxingshi", SqlDbType.NVarChar,50),
         new SqlParameter("@donglisuisuzhuanxiang", SqlDbType.NVarChar,50),
         new SqlParameter("@zhudongzhuanxiangxitong", SqlDbType.NVarChar,50),
         new SqlParameter("@fangxiangpan", SqlDbType.NVarChar,50),
         new SqlParameter("@zuojiaoxiuxitaban", SqlDbType.NVarChar,50),
         new SqlParameter("@fangxiangpantiaojie", SqlDbType.NVarChar,50),
         new SqlParameter("@duogongnengfangxiangpan", SqlDbType.NVarChar,50),
         new SqlParameter("@dingsuxunhang", SqlDbType.NVarChar,50),
         new SqlParameter("@bochefuzhu", SqlDbType.NVarChar,50),
         new SqlParameter("@duogongnengxianshiping", SqlDbType.NVarChar,50),
         new SqlParameter("@zuoyi", SqlDbType.NVarChar,50),
         new SqlParameter("@zuoyitiaojie", SqlDbType.NVarChar,50),
         new SqlParameter("@yaobuzhichengtiaojie", SqlDbType.NVarChar,50),
         new SqlParameter("@qianpaizuoyidiandongtiaojie", SqlDbType.NVarChar,50),
         new SqlParameter("@zuoyijiare", SqlDbType.NVarChar,50),
         new SqlParameter("@qianzuozhongyangfushou", SqlDbType.NVarChar,50),
         new SqlParameter("@houzuozhongyangfushou", SqlDbType.NVarChar,50),
         new SqlParameter("@houpaizuoyianbilifangdao", SqlDbType.NVarChar,50),
         new SqlParameter("@yinxiangxitong", SqlDbType.NVarChar,50),
         new SqlParameter("@yangshengqigeshu", SqlDbType.NVarChar,50),
         new SqlParameter("@GPSdaohangxitong", SqlDbType.NVarChar,50),
         new SqlParameter("@duomeitikongzhixitong", SqlDbType.NVarChar,50),
         new SqlParameter("@chezaidianhua", SqlDbType.NVarChar,50),
         new SqlParameter("@zhongkongtaiyejingping", SqlDbType.NVarChar,50),
         new SqlParameter("@houpaiyejingping", SqlDbType.NVarChar,50),
         new SqlParameter("@MP3zhichi", SqlDbType.NVarChar,50),
         new SqlParameter("@dadeng", SqlDbType.NVarChar,50),
         new SqlParameter("@wudeng", SqlDbType.NVarChar,50),
         new SqlParameter("@qiandiandongchechuang", SqlDbType.NVarChar,50),
         new SqlParameter("@houdiandongchechuang", SqlDbType.NVarChar,50),
         new SqlParameter("@fangjiashougongneng", SqlDbType.NVarChar,50),
         new SqlParameter("@diandonghoushijing", SqlDbType.NVarChar,50),
         new SqlParameter("@houshijingjiare", SqlDbType.NVarChar,50),
         new SqlParameter("@houshijingdiandongzhedie", SqlDbType.NVarChar,50),
         new SqlParameter("@zheyanglian", SqlDbType.NVarChar,50),
         new SqlParameter("@houshijingfangxuanmu", SqlDbType.NVarChar,50),
         new SqlParameter("@zheyangbanhuazhuangjing", SqlDbType.NVarChar,50),
         new SqlParameter("@ganyingyushua", SqlDbType.NVarChar,50),
         new SqlParameter("@kongtiao", SqlDbType.NVarChar,50),
         new SqlParameter("@chufengkou", SqlDbType.NVarChar,50),
         new SqlParameter("@cheneikongqitiaojie", SqlDbType.NVarChar,50),
         new SqlParameter("@chezaibingxiang", SqlDbType.NVarChar,50),
         new SqlParameter("@dianzifangdao", SqlDbType.NVarChar,50),
         new SqlParameter("@cheneizhongkongsuo", SqlDbType.NVarChar,50),
         new SqlParameter("@yaokongyaoshi", SqlDbType.NVarChar,50),
         new SqlParameter("@wuyaoshiqidongxitong", SqlDbType.NVarChar,50),
          new SqlParameter("@title",SqlDbType.NVarChar,50),
          new SqlParameter("@pic",SqlDbType.NVarChar,50),
          new SqlParameter("@pContent",SqlDbType.NText),
          new SqlParameter("@sort",SqlDbType.Int,4),
          new SqlParameter("@CTR",SqlDbType.Int,4)
    };
            parameters[0].Value = model.ProductId;
            parameters[1].Value = model.CategorieId;
            parameters[2].Value = model.ModelId;
            parameters[3].Value = model.Chekuanming;
            parameters[6].Value = model.Zhidaojiage;
            parameters[7].Value = model.Chandi;
            parameters[8].Value = model.Chicun;
            parameters[9].Value = model.Zhouju;
            parameters[10].Value = model.Zuidagonglv;
            parameters[11].Value = model.Zuidaniuju;
            parameters[12].Value = model.Biansuqi;
            parameters[13].Value = model.Zuigaochesu;
            parameters[14].Value = model.Ranyou;
            parameters[15].Value = model.Zongheyouhao;
            parameters[16].Value = model.Zhengbeizhiliang;
            parameters[17].Value = model.Zuowei;
            parameters[18].Value = model.Xinglixiangrongji;
            parameters[19].Value = model.Chemen;
            parameters[20].Value = model.Qianlunju;
            parameters[21].Value = model.Houlunju;
            parameters[22].Value = model.Zuixiaolidijianxi;
            parameters[23].Value = model.Qianxuangua;
            parameters[24].Value = model.Houxuangua;
            parameters[25].Value = model.Qianhouzhidongqileixing;
            parameters[26].Value = model.Qudongfangshi;
            parameters[27].Value = model.Tianchuang;
            parameters[28].Value = model.Cheshenyanse;
            parameters[29].Value = model.Lvhejinlungu;
            parameters[30].Value = model.Paiqiliang;
            parameters[31].Value = model.Yasuobi;
            parameters[32].Value = model.Qigangxingshi;
            parameters[33].Value = model.Fadongjichangjiaxinghao;
            parameters[34].Value = model.Jiasushijian;
            parameters[35].Value = model.Qianhouluntaiguige;
            parameters[36].Value = model.Fengzuxishu;
            parameters[37].Value = model.Anquanqinang;
            parameters[38].Value = model.ABS;
            parameters[39].Value = model.Zhidonglifenpei;
            parameters[40].Value = model.Qianyinlikongzhi;
            parameters[41].Value = model.Taiyajiancezhuangzhi;
            parameters[42].Value = model.Lingtaiyajixuxingshi;
            parameters[43].Value = model.Donglisuisuzhuanxiang;
            parameters[44].Value = model.Zhudongzhuanxiangxitong;
            parameters[45].Value = model.Fangxiangpan;
            parameters[46].Value = model.Zuojiaoxiuxitaban;
            parameters[47].Value = model.Fangxiangpantiaojie;
            parameters[48].Value = model.Duogongnengfangxiangpan;
            parameters[49].Value = model.Dingsuxunhang;
            parameters[50].Value = model.Bochefuzhu;
            parameters[51].Value = model.Duogongnengxianshiping;
            parameters[52].Value = model.Zuoyi;
            parameters[53].Value = model.Zuoyitiaojie;
            parameters[54].Value = model.Yaobuzhichengtiaojie;
            parameters[55].Value = model.Qianpaizuoyidiandongtiaojie;
            parameters[56].Value = model.Zuoyijiare;
            parameters[57].Value = model.Qianzuozhongyangfushou;
            parameters[58].Value = model.Houzuozhongyangfushou;
            parameters[59].Value = model.Houpaizuoyianbilifangdao;
            parameters[60].Value = model.Yinxiangxitong;
            parameters[61].Value = model.Yangshengqigeshu;
            parameters[62].Value = model.GPSdaohangxitong;
            parameters[63].Value = model.Duomeitikongzhixitong;
            parameters[64].Value = model.Chezaidianhua;
            parameters[65].Value = model.Zhongkongtaiyejingping;
            parameters[66].Value = model.Houpaiyejingping;
            parameters[67].Value = model.MP3zhichi;
            parameters[68].Value = model.Dadeng;
            parameters[69].Value = model.Wudeng;
            parameters[70].Value = model.Qiandiandongchechuang;
            parameters[71].Value = model.Houdiandongchechuang;
            parameters[72].Value = model.Fangjiashougongneng;
            parameters[73].Value = model.Diandonghoushijing;
            parameters[74].Value = model.Houshijingjiare;
            parameters[75].Value = model.Houshijingdiandongzhedie;
            parameters[76].Value = model.Zheyanglian;
            parameters[77].Value = model.Houshijingfangxuanmu;
            parameters[78].Value = model.Zheyangbanhuazhuangjing;
            parameters[79].Value = model.Ganyingyushua;
            parameters[80].Value = model.Kongtiao;
            parameters[81].Value = model.Chufengkou;
            parameters[82].Value = model.Cheneikongqitiaojie;
            parameters[83].Value = model.Chezaibingxiang;
            parameters[84].Value = model.Dianzifangdao;
            parameters[85].Value = model.Cheneizhongkongsuo;
            parameters[86].Value = model.Yaokongyaoshi;
            parameters[87].Value = model.Wuyaoshiqidongxitong;
            parameters[88].Value = model.Title;
            parameters[89].Value = model.Pic;
            parameters[90].Value = model.PContent;
            parameters[91].Value = model.Sort;
            parameters[92].Value = model.CTR;

           return  SqlHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }



不知道错在哪里,希望高手帮忙····
搜索更多相关主题的帖子: 界限 SqlParameter 索引 
2010-01-25 18:45
tokoyoshi
Rank: 2
等 级:论坛游民
帖 子:99
专家分:67
注 册:2009-10-24
收藏
得分:0 
自己顶个吧·
2010-01-27 09:16
baikil
Rank: 10Rank: 10Rank: 10
来 自:X星球
等 级:青峰侠
威 望:4
帖 子:282
专家分:1580
注 册:2009-7-20
收藏
得分:20 
为何不使用存储过程为做呢,速度上有比这个快的多,,这个没有怎么困难,只在仔细一点不要写错了就行了,
异常详细信息: System.IndexOutOfRangeException: 索引超出了数组界限。
这上就你的数组大小没有你写的这么长,一定少写了,SqlParameter[] parameters =new SqlParameter[] {...}的长度没有这么大啊,!

自创QQ群64885635,方便C#学习交流.希望各项工作路好学都好入!
2010-01-27 09:31
kennethwang
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2009-10-9
收藏
得分:0 
会不会应该这样写呢?!
SqlParameter[] parameters=new SqlParameter[93]
{
......
}

我只是个初学者,不过我是这么写的。
如有不对见笑。
2010-01-31 09:59
kennethwang
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2009-10-9
收藏
得分:0 
会不会应该这样写呢?!
SqlParameter[] parameters=new SqlParameter[93]
{
......
}

我只是个初学者,不过我是这么写的。
如有不对见笑。
2010-01-31 10:00
kennethwang
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2009-10-9
收藏
得分:0 
会不会应该这样写呢?!
SqlParameter[] parameters=new SqlParameter[93]
{
......
}

我只是个初学者,不过我是这么写的。
如有不对见笑。
2010-01-31 10:01
闻启学
Rank: 2
来 自:宇宙
等 级:论坛游民
帖 子:82
专家分:44
注 册:2009-4-8
收藏
得分:0 
你那么多参数,最好用结构来作参数,
Sql语句用存储过程来做方便些!!!
2010-02-16 10:38
快速回复:关于SqlParameter[] 索引超出了数组界限
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032966 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved