SQL查询的DropDownList [英] sql query and dropdownlist
本文介绍了SQL查询的DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个下拉列表,其中有列的表的值。
I have a drop down list which has the values of column's table.
和我有在C#中声明如下:
and I have the following statement in c#:
string raf = string.Format("select Id from Customer WHERE email="dropdownlist1");
如何分配下拉列表的值,以发送电子邮件?
how can assign the value of the drop down list to email ?
推荐答案
您需要使用 .SelectedValue
属性来获取下拉列表的值: -
You need to use .SelectedValue
property to fetch the value of dropdown:-
string raf = string.Format("select Id from Customer WHERE email={0}",
dropdownlist1.SelectedValue);
有关取下拉文本: -
For fetching dropdown text:-
string raf = string.Format("select Id from Customer WHERE email={0}",
dropdownlist1.SelectedItem.Text);
另外,注意你需要像的占位符{0}
,使用时的String.Format
。
虽然根据您的查询,大多是创下了数据库,因此 SQL注入提防使用参数化查询是这样的: -
Though as per your query, you are mostly hitting a database, so beware of SQL Injection, use parameterized query like this:-
string raf = select Id from Customer WHERE email=@DropdownText;
SqlCommand cmd = new SqlCommand(raf,conn);
cmd.Parameters.Add("@DropdownText",SqlDbType.NVarchar,20).Value =
dropdownlist1.SelectedItem.Text;
这篇关于SQL查询的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文