0

here it does not show any error only page loading what is the error?

C# code

protected void imgs_Click(object sender, ImageClickEventArgs e)  
        {        
            foreach (RepeaterItem ri in repeater.Items)
            {

            CheckBox item_check = (CheckBox)ri.FindControl("item_check");
            Label txt_id = (Label)ri.FindControl("txt_id");

                if (item_check.Checked)
                {
                    con = new SqlConnection(strcon);
                    SqlCommand cmd = new SqlCommand("ram", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    con.Open();
                    cmd.Parameters.AddWithValue("@Action", "DELETE");
                    cmd.Parameters.AddWithValue("@eid", txt_id);
                    repeat();
               }                
        }     
}

asp.code

2
  • Please check aspsnippets.com/Articles/… Commented Dec 2, 2014 at 7:37
  • put it in a try catch block and print out the error in the catch block to see if really no errors are made Commented Dec 2, 2014 at 7:42

2 Answers 2

1

You Forgot To Write cmd.ExecuteNonQuery();

  1. Stop Using AddWithValue
  2. Always use using for SqlConnection and SqlCommand which implements IDisposable

    protected void imgs_Click(object sender, ImageClickEventArgs e)
    {

        foreach (RepeaterItem ri in repeater.Items)
        {
    
        CheckBox item_check = (CheckBox)ri.FindControl("item_check");
        Label txt_id = (Label)ri.FindControl("txt_id");
    
            if (item_check.Checked)
            {
          Using(SqlConnection con = new SqlConnection(strcon))
                {
          Using(SqlCommand cmd = new SqlCommand("ram", con))
                 {
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                cmd.Parameters.Add("@Action",SqlDbType.Varchar,50).Value="DELETE";
                cmd.Parameters.Add("@eid",SqlDbType.Int).Value=Convert.ToInt16(txt_id.Text);
                cmd.ExecuteNonQuery();
               repeat();
                }
               }
           }                
    }     
    

    }

Sign up to request clarification or add additional context in comments.

1 Comment

i m getting this error Collection was modified; enumeration operation may not execute.
0
    foreach (RepeaterItem ri in repeater.Items)
    {

        CheckBox item_check = (CheckBox)ri.FindControl("item_check");
        Label txt_id = (Label)ri.FindControl("txt_id");

        if (item_check.Checked)
        {

            con = new SqlConnection(strcon);
            cmd = new SqlCommand("ram", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Action", "DELETE");
            cmd.Parameters.AddWithValue("@eid", txt_id.Text);
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            finally
            {

                con.Close();
            }
        }
    }
    repeat();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.