datalist中如何根据自己的选择删除选定的内容
当我执行了sql语句时,count dep_id dep_name
5 1 人事部
.......
当我要删除部门名"bb",此时部门bb里并无员工
public void DataList_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
string str="select count(*) as count,users.dep_id,dep_name from users,dep where users.dep_id=dep.dep_id group by users.dep_id,dep_name";
com=new SqlCommand(str,conn);
conn.Open();
SqlDataReader dr=com.ExecuteReader();
while(dr.Read())
{
int count = Convert.ToInt32(dr["count"]); //count=5 ???
string depname=dr["dep_name"].ToString();
if(count==0)
{string str1="delete * from dep where dep_name=depname";
com1=new SqlCommand(str1,conn);
com1.ExecuteNonQuery();}
else
{
Response.Write("<script>javascript:alert('该部门里还有员工,不允许删除!!!');window.location='dep_manage.aspx'</script>"); //跳到这一步
}
}
dr.Close();
conn.Close();
ListBind();
}
[此贴子已经被作者于2007-6-2 13:53:47编辑过]