我要实现一个简单的查询,在DropDownList中add一些值。怎么才能够实现以选中的值为参数,来查询数据库中相关的数据?并返回查询结果?用的是SQLSERVER数据库!

解决方案 »

  1.   

    select * from temp where proname like '%" + searchkey + "%'";
    searchkey为变量.
      

  2.   

    protected System.Web.UI.WebControls.Button btnClick;
    protected System.Web.UI.WebControls.DropDownList dropAuthors;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (! IsPostBack ) 
    {
    SqlConnection conPubs;
    SqlCommand cmdSelect;
    SqlDataReader dtrAuthors; conPubs = new SqlConnection( @"Server=localhost;uid=sa;pwd=sa;Database=Pubs" );
    conPubs.Open();
    cmdSelect = new SqlCommand( "Select au_id, au_lname From Authors", conPubs );
    dtrAuthors = cmdSelect.ExecuteReader(); dropAuthors.DataSource = dtrAuthors;
    dropAuthors.DataTextField = "au_lname";
    // dropAuthors.DataValueField = "au_id";
    dropAuthors.DataBind(); dtrAuthors.Close();
    conPubs.Close();
    }
    } private void btnClick_Click(object sender, System.EventArgs e)
    {
    Response.Write("作者的id为:" + dropAuthors.SelectedValue);
    Response.Write("<br>");
    Response.Write("作者的姓名为:" + dropAuthors.SelectedItem.Text);
    }
      

  3.   

    select * from table(你的表名) where aa(你的第一个列名) like '%"+this.DropList1.SelectedItem.Text+"%' or  bb(你的第二个列名) like '%"+this.DropList1.SelectedItem.Text+"%'  or ................