SqlCommand cmd=new SqlCommand("delete from question,answer where  question.num='"+num+"'and  question.name=answer.name ",con);
-----------------------------------------------
SqlCommand cmd=new SqlCommand("delete from question,answer where  question.num='"+num+"'and  question.name='"+answer.name+"' ",con);

解决方案 »

  1.   

    删除是不能 delete from question,answer 这样连着两个表的
      

  2.   

    你必须根据你的条件先删除光了从表(answer)的所有记录,然后才能删除主表(question)的记录,尤其如果你的数据库里有主外键的约束的话,默认是不能级联删除的
      

  3.   

    改成
    SqlCommand cmd1=new SqlCommand("delete from answer   where question.name=answer.name and question.num='"+num+"'",con);
    cmd1.ExecuteNonQuery();
    SqlCommand cmd=new SqlCommand("delete from question  where num='"+num+"'",con);
    cmd.ExecuteNonQuery();出现列前缀 'question' 与查询中所用的表名或别名不匹配。
      

  4.   

    建立Relation关系后,自动会帮你删除的