//获取跳转信息
        this.lblclass.Text = Convert.ToString(Session["Class"]);
        this.lblclasscode.Text = Convert.ToString(Session["ClassCode"]);
        this.lblname.Text = Convert.ToString(Session["Name"]);
        this.lblasid.Text = Request.QueryString["as_id"].ToString();
        string as_idst=this.lblasid.Text.ToString();
        string name=this.lblname.Text.ToString();
        //获取学生学号   
        SqlConnection con = new SqlConnection("server=.;database=Graduate;uid=sa;pwd=;");
        con.Open();
        string getst_name = this.lblname.Text.ToString();
        string getst_id = Session["username"].ToString();            string cmdateset = "select top 1 * from stu_poll  where as_id in('"+getas_id+"') and st_id in(  select StudentID from Student where Name='" + getst_name +"' )";
           
            SqlDataAdapter mysda = new SqlDataAdapter(cmdateset, con);
            DataSet myds = new DataSet();
            mysda.Fill(myds, "Sum");
            int SumA = Convert.ToInt32(myds.Tables["Sum"].Rows[0]["A"].ToString());
            int SumB = Convert.ToInt32(myds.Tables["Sum"].Rows[0]["B"].ToString());
            int SumC = Convert.ToInt32(myds.Tables["Sum"].Rows[0]["C"].ToString());
            int SumD = Convert.ToInt32(myds.Tables["Sum"].Rows[0]["D"].ToString());
            string score = Convert.ToString((SumA * 10) + (SumB * 8) + (SumC * 6) + (SumD * 4));            //将分数存入到score表中            string insert = "insert into stu_score (as_id,sn,score,class_id) values ('" + getas_id + "','" + getst_id + "','" + score + "','" + getcl_id + "')";
          
            SqlCommand insercmd = new SqlCommand(insert, con);
            insercmd.ExecuteNonQuery();
           
            //insercmd.ExecuteNonQuery(); 出现错误 说:"子查询返回的值多于一个.当子查询跟随在=、!=、 <、 <=、> 、> =之后,或子查询用作表达式时,这种情况是不允许的! " 
        

解决方案 »

  1.   

    string cmdateset = "select top 1 * from stu_poll where as_id in('"+getas_id+"') and st_id in( select StudentID from Student where Name='" + getst_name +"' )";这个拼的sql有问题
      

  2.   

    建议用string。format这样问题会少很多
      

  3.   

    参考: string insert = String.Format("insert into stu_score (as_id,sn,score,class_id) values ('{0}','{1}','{2}','{3}')", getas_id, getst_id, score, getcl_id);
      

  4.   

    还是用format 好点。这样有序点,不容易出错,不需要你添加引号,很方便!
      

  5.   

    sqlParameter
    insert,cmdateset 在查询分析器执行看看
    数据表中是否有相同的行
      

  6.   

    把 拼接完的 sql 语句   Response.Write 到页面上,复制到sql上去运行一下
      

  7.   

     string cmdateset = "select top 1 * from stu_poll where as_id in('"+getas_id+"') and st_id in( select StudentID from Student where Name='" + getst_name +"' )";在这一句加断点,监视,取值到SQL查询分析器去执行下,改为以下代码试试:
     string cmdateset = "select top 1 * from stu_poll where as_id in("+getas_id+") and st_id in( select StudentID from Student where Name='" + getst_name +"' )";
      

  8.   

    断点调试,
    把sql语句复制都查询分析器上看看。
      

  9.   

    string cmdateset = "select top 1 * from stu_poll where as_id in('"+getas_id+"') and st_id in( select max(StudentID) from Student where Name='" + getst_name +"' )";
      

  10.   

    这个出现问题是因为 你select过后返回的记录不唯一(即本来应该返回一条记录,你返回了多条,造成了后面处理的混乱)建议可以在sql里面写存储过程 好看点
      

  11.   

    和=、!=、 <、 <=、> 、> =作比较的数有且只能有一个
    你的子查询中返回了多个值,你让它们怎么比较呢?
      

  12.   

    应该是这样的:(3,8,9,10,-1,-4) > 3而不该是:(3,8,9,10,-1,-4) > (3,5)
      

  13.   

    建议用jion on连接查询,连接查询和子查询的结果是一样的