dr=com.ExecuteReader();
while(dr.Read())
{
int Count=Convert.toInt32(dr["count"]);
if(Count==0)
{string str1="delete * from dep where "}
}
我想实现的功能:
当部门aa中有员工时,不允许删除;若没有员工,则允许删除
com.commandstring="delete * from dep where " 好像是 这个commandstring属性!你找下 有这个属性设置的!
com.ExecuteReader();
先给datalist设置DataKey
string Delstring=DataList1.DataKeys[e.Item.ItemIndex];
string str1="delete * from dep where id='"+Delstring+"'";//这里你要把datakey设置为条件where的字段。
判断是否有数据,别像你那样判断。。
--------------------------------------------------------
string Delstring=DataList1.DataKeys[e.Item.ItemIndex];
int count=0;
string Countsql="select users.dep_id,dep.dep_name from users,dep where users.dep_id=dep.dep_id group by users.dep_id,dep.dep_name";
SqlCommand cmd = new SqlCommand(Countsql,conn);
count = Convert.ToInt16(cmd.ExecuteScalar());
if(count>0)
{
string str1="delete * from dep where id='"+Delstring+"'";
SqlCommand cmd1= new SqlCommand(str1,conn)
cmd1.ExecuteNonQuery();
}
else
{
Response.Write("<script>javascript:alert('该部门里还有员工,不允许删除!!!');window.location='dep_manage.aspx'</script>");
}