这里它没有显示任何错误,只有页面加载错误是什么?
C#代码
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
答案 0 :(得分:1)
您忘了写cmd.ExecuteNonQuery();
AddWithValue
始终使用using
SqlConnection
和SqlCommand
实施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();
}
}
}
}
}
答案 1 :(得分: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();