很急的问题

baobao521 2009-12-18 02:26:48
现在项解决的的问题是:查询出学科成绩表分数大于一个textbox值,而这些学科绑定在一个dropdownlist控件上。
这个查询语句怎么写呢?老说我输入字符串格式不对
string courseMark = ddl.SelectedValue.ToString().Trim();
int normal =Convert.ToInt32(add2.Text.ToString().Trim());
SqlConnection sqlCon = new SqlConnection("Data Source=localhost; Integrated Security=SSPI; Initial Catalog=student;");
string strSql = "select * from studentTable where '"+courseMark+"'>='" +normal+"'";
我自己感觉问题也蛮大的,但是就是不知道怎么加引号。菜鸟求救了。
...全文
164 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
bj_kevin51 2009-12-18
  • 打赏
  • 举报
回复

string strSql = "select * from studentTable where '"+courseMark+"'>='" +normal+"'";


问题太大。
1.where '"+courseMark+"' 这个后面跟的是数据库字段,你怎么用变量?显然不识别
2.'" +normal+"' 这个东西是变量既不需要加单引号,
3.我不知道你什么意思,为什么定义string类型跟int类型比较,自己搞晕自己。
tan124 2009-12-18
  • 打赏
  • 举报
回复
字段名怎么可以用引号,
alianghao 2009-12-18
  • 打赏
  • 举报
回复
字段名怎么可以用引号,
zqtoo 2009-12-18
  • 打赏
  • 举报
回复
"select * from studentTable where "+courseMark+" >= "+ normal;
zqtoo 2009-12-18
  • 打赏
  • 举报
回复
字段名 和 数值 不要加 单引号
jaguar_yang 2009-12-18
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 jaguar_yang 的回复:]
C# codestring strSql="select * from studentTable where"+courseMark+">="+ normal;
[/Quote]



string strSql = "select * from studentTable where courseMark >= " + normal;
jaguar_yang 2009-12-18
  • 打赏
  • 举报
回复

string strSql = "select * from studentTable where "+courseMark+">=" + normal;
Pra_lijian 2009-12-18
  • 打赏
  • 举报
回复
string.Format("string.select * from studentTable where courseMark >= {0}",normal);
baobao521 2009-12-18
  • 打赏
  • 举报
回复
normal是自己通过textbox输入的一个整形数值。前面的DROPDWNLIST绑定的是ftp://cfswt.com/%CD%BC07.pngcurseName字段,值与ftp://cfswt.com/%CD%BC07.png中的englishmark,mathmark相匹配

lihuaandzz 2009-12-18
  • 打赏
  • 举报
回复
int normal =int.parst(add2.Text.ToString().Trim())
chengcheng1253 2009-12-18
  • 打赏
  • 举报
回复
比如你数据库是这样的
ID value
1 111
2 222
3 333

那你按照ID 找的话 就是string strSql = "select * from studentTable where ID >= " +normal ;
wsj1983920 2009-12-18
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 baobao521 的回复:]
编译不出错,就是页面输入textbox值,点查询后一直报错int normal =Convert.ToInt32(add2.Text.ToString().Trim());此处输入字符串的格式不正确。
[/Quote]add2.Text 写正则限制只能输入数字
wsj1983920 2009-12-18
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 baobao521 的回复:]
编译不出错,就是页面输入textbox值,点查询后一直报错int normal =Convert.ToInt32(add2.Text.ToString().Trim());此处输入字符串的格式不正确。
[/Quote]你能吧ssss 这样的字符串转化成数字啊。。。不报错就怪了
chengcheng1253 2009-12-18
  • 打赏
  • 举报
回复
你数据库中对应的int normal的值的字段的名称是什么?
baobao521 2009-12-18
  • 打赏
  • 举报
回复
编译不出错,就是页面输入textbox值,点查询后一直报错int normal =Convert.ToInt32(add2.Text.ToString().Trim());此处输入字符串的格式不正确。
baobao521 2009-12-18
  • 打赏
  • 举报
回复
恩。主要是现在不会改,谁有办法,
lihuaandzz 2009-12-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 baobao521 的回复:]
改了也不对啊。是'"+CONVERT.TOInt32(courseMark)+"'吗?
[/Quote]

改了之后把单引号去掉试试
string strSql = "select * from studentTable where "+courseMark+">=" +normal+"";
wsj1983920 2009-12-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 baobao521 的回复:]
改了也不对啊。是'"+CONVERT.TOInt32(courseMark)+"'吗?
[/Quote]normal.tostring
chengcheng1253 2009-12-18
  • 打赏
  • 举报
回复
[Quote=引用楼主 baobao521 的回复:]
string strSql = "select * from studentTable where '"+courseMark+"'>='" +normal+"'"; [/Quote]】
这个有问题~
baobao521 2009-12-18
  • 打赏
  • 举报
回复
改了也不对啊。是'"+CONVERT.TOInt32(courseMark)+"'吗?
加载更多回复(4)

62,254

社区成员

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

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

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

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