string[] strSql = new string[] { };
int id;
int j = 0;
for (int i = 0; i < gdvkcssDict.Rows.Count; i++)
{
if (((CheckBox)(gdvkcssDict.Rows[i].Cells[0].FindControl("chkOne"))).Checked)
{ id = Convert.ToInt32(gdvkcssDict.Rows[i].Cells[1].Text);
if (j < 10)
{
strSql[j] = " delete from kcssDict where kcdictID=" + id;
j++;
}else
Response.Write("<script>alert('修改失败!');window.location= 'jump.aspx';</script>");
}
}大家帮我看看到底怎么回事,
int id;
int j = 0;
for (int i = 0; i < gdvkcssDict.Rows.Count; i++)
{
if (((CheckBox)(gdvkcssDict.Rows[i].Cells[0].FindControl("chkOne"))).Checked)
{ id = Convert.ToInt32(gdvkcssDict.Rows[i].Cells[1].Text);
if (j < 10)
{
strSql[j] = " delete from kcssDict where kcdictID=" + id;
j++;
}else
Response.Write("<script>alert('修改失败!');window.location= 'jump.aspx';</script>");
}
}大家帮我看看到底怎么回事,
出问题的是这行
strSql[j] = " delete from kcssDict where kcdictID=" + id;
j++;
string[] strSql = new string[gdvkcssDict.Rows.Count];
int id;
int j = 0;
for (int i = 0; i < gdvkcssDict.Rows.Count; i++)
{
if (((CheckBox)(gdvkcssDict.Rows[i].Cells[0].FindControl("chkOne"))).Checked)
{ id = Convert.ToInt32(gdvkcssDict.Rows[i].Cells[1].Text);
if (j < 10)
{
strSql[j] = " delete from kcssDict where kcdictID=" + id;
j++;
}else
Response.Write("<script>alert('修改失败!');window.location= 'jump.aspx';</script>");
}
}
你这句话定义了一个长度为0的数组,后面又用strSql[1],strSql[2]....
肯定越界了!
string[] strSql = new string[10];
这样就可以 了
var strSqls = "";
int id;
int j = 0;
for (int i = 0; i < gdvkcssDict.Rows.Count; i++)
{
if (((CheckBox)(gdvkcssDict.Rows[i].Cells[0].FindControl("chkOne"))).Checked)
{ id = Convert.ToInt32(gdvkcssDict.Rows[i].Cells[1].Text);
if (j < 10)
{
strSqls += " delete from kcssDict where kcdictID=" + id + "|";
j++;
}
else
Response.Write("<script>alert('修改失败!');window.location= 'jump.aspx';</script>");
}
}
if (strSqls.Length == 0)
{
Response.Write("<script>alert('没有需要修改的数据!');window.location= 'jump.aspx';</script>");
} string[] strSql = strSqls.Remove(strSqls.Length - 2).Split('|');// 这样strSql中没有多余无用的数据或空的数据了