"子查询返回的值多于一个.当子查询跟随在=、!=、 <、 <=、> 、> =之后,或子查询用作表达式时,这种情况是不允许的! "

灵动眼镜 2010-04-30 02:27:37
//获取跳转信息
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(); 出现错误 说:"子查询返回的值多于一个.当子查询跟随在=、!=、 <、 <=、> 、> =之后,或子查询用作表达式时,这种情况是不允许的! "
...全文
1046 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
kinglot 2010-05-01
  • 打赏
  • 举报
回复
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 +"' )";
libinlink 2010-05-01
  • 打赏
  • 举报
回复
应该是这样的:(3,8,9,10,-1,-4) > 3

而不该是:(3,8,9,10,-1,-4) > (3,5)
libinlink 2010-05-01
  • 打赏
  • 举报
回复
和=、!=、 <、 <=、> 、> =作比较的数有且只能有一个
你的子查询中返回了多个值,你让它们怎么比较呢?
tashiwoweiyi 2010-05-01
  • 打赏
  • 举报
回复
节日快乐
dogstar901 2010-05-01
  • 打赏
  • 举报
回复
这个出现问题是因为 你select过后返回的记录不唯一(即本来应该返回一条记录,你返回了多条,造成了后面处理的混乱)

建议可以在sql里面写存储过程 好看点
antiking 2010-05-01
  • 打赏
  • 举报
回复
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 +"' )";
vip__888 2010-05-01
  • 打赏
  • 举报
回复
断点调试,
把sql语句复制都查询分析器上看看。
xianfeng94 2010-05-01
  • 打赏
  • 举报
回复
节日快乐
zhanshenjsb 2010-05-01
  • 打赏
  • 举报
回复
建议用jion on连接查询,连接查询和子查询的结果是一样的
wanghuaide 2010-04-30
  • 打赏
  • 举报
回复
学习了
wellst 2010-04-30
  • 打赏
  • 举报
回复
把 拼接完的 sql 语句 Response.Write 到页面上,复制到sql上去运行一下。。。
wuyq11 2010-04-30
  • 打赏
  • 举报
回复
sqlParameter
insert,cmdateset 在查询分析器执行看看
数据表中是否有相同的行
puzhichen 2010-04-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 q107770540 的回复:]
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);
[/Quote]
zhangguofang1129 2010-04-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 q107770540 的回复:]

参考:

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);
[/Quote]
可行
wujiche 2010-04-30
  • 打赏
  • 举报
回复
建议使用试图做
xlzhouc 2010-04-30
  • 打赏
  • 举报
回复
还是用format 好点。这样有序点,不容易出错,不需要你添加引号,很方便!
singincloud 2010-04-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 q107770540 的回复:]

参考:

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);
[/Quote]

这个应该是对的
q107770540 2010-04-30
  • 打赏
  • 举报
回复
参考:

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);
singincloud 2010-04-30
  • 打赏
  • 举报
回复
建议用string。format这样问题会少很多
kk297173176 2010-04-30
  • 打赏
  • 举报
回复
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有问题

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧