在这里它不显示任何错误,只有页面加载是什么错误?
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
你忘了写cmd.ExecuteNonQuery();
- 停止使用
AddWithValue
-
始终使用
using
进行SqlConnection
和实现IDisposable
的SqlCommand
受保护的无效imgs_Click(对象发送器,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(); } } } }
}
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();