20分求一简单的查询解决方法

20分求一简单的查询
我页面上有一个DropDownList   一个TextBox,和一个按钮
比如我先在DropDownList选择一个比如姓名,然后在TextBox里输入一个名字,然后点查询按钮
代码如下OleDbCommand   cmd   =   new   OleDbCommand( "select   *   from   student   where   ' "+DropDownList1.SelectedValue+ " '   = ' "+TextBox1.Text   + " ' ",   con);

DropDownList1.SelectedValue的值是Name
但是读不出来
只有直接把DropDownList1.SelectedValue换成Name才行
请问该怎么办?


------解决方案--------------------
SQL写错了,DropDownList的值不需要加 '号,改成
"select * from student where " + DropDownList1.SelectedValue + " = ' " + TextBox1.Text + " ' "
另外,这种方法没有考虑SQL注入的问题,要小心安全问题
------解决方案--------------------
换个方法嘛,先定义一个变量,把DropDownList1的值赋给它,然后在把变量放进sql语句中比较,这种sql语句不容易出错。
textbox1.text也一样处理。比较好。
------解决方案--------------------
SQL写错了,DropDownList的值不需要加 '号,改成
"select * from student where " + DropDownList1.SelectedValue + " = ' " + TextBox1.Text + " ' "
另外,这种方法没有考虑SQL注入的问题,要小心安全问题
=====================================================
正解,TextBox1.Text 最好用参数
------解决方案--------------------
OleDbCommand cmd = new OleDbCommand( "select * from student where ' "+DropDownList1.SelectedValue+ " ' = ' "+TextBox1.Text + " ' ", con);

' "+DropDownList1.SelectedValue+ " ' 这里加了‘’ 肯定是错误的
你的sql 就变成

select * from student where 'Name ' = ' " + TextBox1.Text + " '

-------------------------------------------

string _sStrSql = "select * from student where "+DropDownList1.SelectedValue.ToString()+ " = ' "+TextBox1.Text.Trim() + " ' ";
OleDbCommand cmd = new OleDbCommand(_sStrSql,con);

这样单独调试看看,取道的_sStrSql 值是什么
------解决方案--------------------
DropDownList1.SelectedText.ToString()+ "