private void Button2_Click(object sender, System.EventArgs e)
{
for(int j=0;j<CheckBoxList2.Items.Count;j++)
{
if(CheckBoxList2.Items[j].Selected==true)
{
string aaa=CheckBoxList2.Items[j].Value.Trim();
for(int i=0;i<CheckBoxList1.Items.Count;i++)
{
if(CheckBoxList1.Items[i].Selected==true)
{

string cc=CheckBoxList1.Items[i].Value.Trim();

for(int k=0;k<DataGrid1.Items.Count;k++)
{

string studentid=((Label)DataGrid1.Items[k].FindControl("Label3")).Text;
string strSQL="select * from kaoshi_result where grade_name='"+DropDownList2.SelectedItem.Value+"' and class_name='"+aaa+"' and kaoshi_code='"+DropDownList1.SelectedItem.Value+"' and id='"+studentid+"'";
SqlDataAdapter da=new SqlDataAdapter(strSQL,myConnection);
DataSet ds=new DataSet();
da.Fill(ds,"database");
string dd=ds.Tables["database"].Rows[0][""+cc+""].ToString();
string oldzf=ds.Tables["database"].Rows[0]["zhongfen2"].ToString();

float ff=float.Parse(oldzf)+float.Parse(dd);
string updateCmd = "UPDATE kaoshi_result set zhongfen2='"+ff+"' where id='"+studentid+"'";
SqlCommand myCommand2=new SqlCommand(updateCmd,myConnection);
myCommand2.Connection.Open();
myCommand2.ExecuteNonQuery();
myConnection.Close();
myCommand2.Connection.Close();

}



}
}
}
}
Label5.Text="参考科目总分处理完毕";
Button2.Enabled=false;
} private void Button8_Click(object sender, System.EventArgs e)
{
for(int k=0;k<DataGrid1.Items.Count;k++)
{
Button8.Attributes ["onclick"]="javascript:return confirm('是否删除?');";
//string studentid=((Label)DataGrid1.Items[k].FindControl("Label3")).Text;
string strCommand="delete from kaoshi_result where grade_name='"+DropDownList2.SelectedItem.Value+"' and kaoshi_code='"+DropDownList1.SelectedItem.Value+"' and yw='-1' and sx='-1' and wy='-1'";
SqlCommand myCommand=new SqlCommand(strCommand,myConnection);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();

}
Response.Write("<script language=Javascript>");
Response.Write("alert('记录删除成功!');");
Response.Write("</script>");
}

解决方案 »

  1.   

    在位置 0 处没有任何行。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IndexOutOfRangeException: 在位置 0 处没有任何行。源错误: 
    行 322: DataSet ds=new DataSet();
    行 323: da.Fill(ds,"database");
    行 324: string dd=ds.Tables["database"].Rows[0][""+cc+""].ToString();
    行 325: string oldzf=ds.Tables["database"].Rows[0]["zhongfen"].ToString();
    行 326: //string oldzf=((Label)DataGrid1.Items[k].FindControl("Label2")).Text;
     源文件: d:\site\manage\sys\chengjichuli.aspx.cs    行: 324 
      

  2.   

    应该是没有数据被读出吧.
    你的sql语句对不对啊,有没有选择出数据出来?
      

  3.   

    我把第一个循环就是CheckBoxList2去掉或者不选择CheckBoxList2,那么就能执行了。
      

  4.   

    之前做一个判断
    if(ds.Tables["database"].Rows.Count>0)
    {
      你的操作
    }
    else
    {
      表示没有取到数据.
    }