aa = "select * from ceshi where " + this.DropDownList1.SelectedValue + "='" + this.TextBox1.Text.Trim() +"'";
aa = "select * from ceshi where '" + this.DropDownList1.SelectedValue + "'='" +this.TextBox1.Text.Trim() +"'";
aa = "select * from ceshi where '" + this.DropDownList1.SelectedValue + "'=''"+this.TextBox1.Text.Trim() +"''";
第一条是对的,但文本变量this.DropDownList1.SelectedValue好像要用''引起来才行,如第二句,为什么可以不引起来;但第二句查询不到,因为我的this.TextBox1.Text.Trim()只输入数字,好像也要用''引起来才行(不知对不对,但"select * from ceshi where id='1'"是行的),如第三句;但第三句执行是错的,语法错误 (操作符丢失) 在查询表达式 ''id'=''1''' 中,这是什么问题?请高手帮忙!!
aa = "select * from ceshi where '" + this.DropDownList1.SelectedValue + "'='" +this.TextBox1.Text.Trim() +"'";
aa = "select * from ceshi where '" + this.DropDownList1.SelectedValue + "'=''"+this.TextBox1.Text.Trim() +"''";
第一条是对的,但文本变量this.DropDownList1.SelectedValue好像要用''引起来才行,如第二句,为什么可以不引起来;但第二句查询不到,因为我的this.TextBox1.Text.Trim()只输入数字,好像也要用''引起来才行(不知对不对,但"select * from ceshi where id='1'"是行的),如第三句;但第三句执行是错的,语法错误 (操作符丢失) 在查询表达式 ''id'=''1''' 中,这是什么问题?请高手帮忙!!
解决方案 »
- ASPOSE的用法
- chm ,如何能弄出文件夹的功能啊
- 想把html代码在.net 的cs文件中输出,怎么写呢?
- 《C#字符串和正则表达式参考手册》 下载
- .net2.0 GridView显示固定行和空数据显示表头
- 比较简单的2个问题:1、如何取到删除列的值;2如何在DataGrid中加window.open()
- 如何在aspx.cs文件中加入以下代码??
- 请思归、快乐王子等高手帮我看看这个js文件。急!
- 回车事件的处理顺序
- 天哪,都是IE6,竟然显示的字体大小不同。
- <asp:TextBox Text="<%=base.GetText()%>" />有没有合适的写法?
- 如何在ASP.NET里面将SQL数据库里面的数据导出到EXCE或者将EXCEL里面数据导入到SQL表中
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
aa = "select * from ceshi where " + this.DropDownList1.SelectedValue + "=" + this.TextBox1.Text.Trim() +";
============
因为我的this.TextBox1.Text.Trim()只输入数字,好像也要用''引起来才行=====================
即使你输入的是数字,但是你没有类型转换呀,所以还是字符串啦。
应当是 "id=1" ,跟踪调试一下,稍稍改改即可
aa = "select * from ceshi where [" + this.DropDownList1.SelectedValue + "]='" + this.TextBox1.Text.Trim() + "'";
aa = "select * from ceshi where [" + this.DropDownList1.SelectedValue + "]='" +
this.TextBox1.Text.Trim() +"'";
aa = "select * from ceshi where [" + this.DropDownList1.SelectedValue + "]='" +
this.TextBox1.Text.Trim() +"'";
如果DropDownList1.SelectedValue是列名称的话,则上面代码不会出错,你可以试试