请问各位大侠如何进行多值查询!谢谢!
我采用的是多个下拉列表进行选择查询值后,点击查询后完成查询功能!
注:我是用的asp vbscript来完成的,我是个新手,请大家尽量写得详细一点,谢谢!

解决方案 »

  1.   

    给你一个完整的无刷新XMLHTTP实现二级联动下拉框的完整示例,你参考一下,根据意思,可轻易做出多级来.
    以下为页面代码:<form id="Form1" method="post" runat="server">
    <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
    <asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    //以XML求取数据
    function XmlPost(obj)
    {
      var svalue = obj.value;
      var webFileUrl = "?brc_id=" + svalue;
      var result = "";
      var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
      xmlHttp.open("POST", webFileUrl, false);
      xmlHttp.send("");
      result = xmlHttp.responseText;
      
      if(result != "")
      {
        document.all("DropDownList2").length=0;
        var piArray = result.split(",");
        for(var i=0;i<piArray.length;i++)
        {
          var ary1 = piArray[i].toString().split("|");
          //alert(ary1[0].toString());
          document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
        }
      }
      else
      {
        alert(result);
      }
    }
    //-->
    </SCRIPT>    
    </form>以下为后台代码:private System.Data.OleDb.OleDbConnection conn;private DataTable get_dt(string sql)
    {
      string connstr = "Provider=MSDAORA.1;Password=aqjc;User ID=aqjc;Data Source=aqjc";
      this.conn = new OleDbConnection(connstr);
      this.conn.Open();
      OleDbCommand myOleDbCommand = new OleDbCommand(sql,this.conn);
      OleDbDataAdapter myData = new OleDbDataAdapter(myOleDbCommand);  DataSet myDataset = new DataSet();
      try
      {
        myData.Fill(myDataset);
      }
      catch(Exception ex)
      {
        throw ex;
      }  this.conn.Close();
      return myDataset.Tables[0];  
    }private void Page_Load(object sender, System.EventArgs e)
    {
      string brc_id = this.Request.QueryString["brc_id"];
      if(brc_id + "a" != "a")
      {
        this.down2_bind(brc_id);
      }  if(!this.IsPostBack)
      {
        this.down1_bind();
      }
    }/// <summary>
    /// 返回第2个下拉框需要的值给xmlhttp
    /// </summary>
    /// <param name="brc_id"></param>
    private void down2_bind(string brc_id)
    {
      string mystr = "";
      string sql = "select brc_id,brc_name from asm_branch where brc_parentid = '" + brc_id + "'";
      DataTable mytab = this.get_dt(sql);  if(mytab.Rows.Count != 0)
      {
        for(int i=0;i<mytab.Rows.Count;i++)
        {
          mystr += "," + mytab.Rows[i][0].ToString() + "|" + mytab.Rows[i][1].ToString();
        }
        mystr = mystr.Substring(1);
      }
      this.Response.Write(mystr);
      this.Response.End();
    }/// <summary>
    /// 绑定第一个下拉框
    /// </summary>
    private void down1_bind()
    {
      string sql = "select brc_id,brc_name from asm_branch where brc_level = '1'";
      DataTable mytab = this.get_dt(sql);
      this.DropDownList1.DataSource = mytab;
      this.DropDownList1.DataValueField = "brc_id";
      this.DropDownList1.DataTextField = "brc_name";
      this.DropDownList1.DataBind();
      this.DropDownList1.Attributes.Add("onchange","XmlPost(this);");
    }
      

  2.   

    不好意思,能不能用个简单一点的sql语句来写啊
    我对java script不大懂
    请大家尽量帮帮忙啊,急用啊
      

  3.   

    你把上面的JS脚本换成VB脚本即可.如下:<SCRIPT LANGUAGE="vbScript">
    <!--
    '以XML求取数据
    function XmlPost(obj)
    dim svalue 
    svalue = obj.value
    dim webFileUrl 
    webFileUrl = "?brc_id=" + svalue
    dim result
    set xmlHttp = CreateObject("Microsoft.XMLHTTP")
    call xmlHttp.open("POST", webFileUrl, false)
    call xmlHttp.send("")
    result = xmlHttp.responseText set downlist = document.all("DropDownList2") if result <> "" then
    document.all("DropDownList2").length=0
    dim piArray ,ary1
    piArray = split(result,",")
    for i=0 to piArray.length - 1
    ary1 = split(piArray(i),"|")
    downlist.length = downlist.length + 1
    downlist.options(downlist.length-1).text = ary1(1)
    downlist.options(downlist.length-1).value = ary1(0)
    next
    else
    alert(result)
    end if
    end function
    //-->
    </SCRIPT>
      

  4.   

    //************************前台
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
    <asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    //以XML求取数据
    function XmlPost(obj)
    {
       var svalue = obj.value;
       var webFileUrl = "?id=" + svalue;
       var result = "";
       var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
       xmlHttp.open("POST", webFileUrl, false);
       xmlHttp.send("");
       result = xmlHttp.responseText;
      
       if(result != "")
       {
         document.all("DropDownList2").length=0;
         var piArray = result.split(",");
         for(var i=0;i<piArray.length;i++)
         {
           var ary1 = piArray[i].toString().split("|");
           //alert(ary1[0].toString());
           document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
         }
       }
       else
       {
         alert(result);
       }
    }
    //-->
    </SCRIPT>
    </form>
    </body>
    </HTML>
    //*****************后台
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    namespace WebApplication1
    {
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DropDownList DropDownList1;
    protected System.Web.UI.WebControls.DropDownList DropDownList2;

    private System.Data.SqlClient.SqlConnection conn; private DataTable get_dt(string sql)
    {
       string connstr = "server=localhost;database=meng;uid=sa;pwd=sa";
       this.conn = new SqlConnection(connstr);
       this.conn.Open();
       SqlCommand myOleDbCommand = new SqlCommand(sql,this.conn);
       SqlDataAdapter da = new SqlDataAdapter(myOleDbCommand);   DataSet ds = new DataSet();  
         da.Fill(ds);      this.conn.Close();
       return ds.Tables[0];  
    }private void Page_Load(object sender, System.EventArgs e)
    {
       string id = this.Request.QueryString["id"];
       if(id + "a" != "a")
       {
         this.down2_bind(id);
       }   if(!this.IsPostBack)
       {
         this.down1_bind();
       }
    }/// <summary>
    /// 返回第2个下拉框需要的值给xmlhttp
    /// </summary>
    /// <param name="brc_id"></param>
    private void down2_bind(string id)
    {
       string mystr = "";
       string sql = "select * from city where Provinceid = '" + id + "'";
       DataTable mytab = this.get_dt(sql);   if(mytab.Rows.Count != 0)
       {
         for(int i=0;i<mytab.Rows.Count;i++)
         {
          mystr += "," + mytab.Rows[i][0].ToString() + "|" + mytab.Rows[i][1].ToString();
         }
         mystr = mystr.Substring(1);
       }
       this.Response.Write(mystr);
       this.Response.End();
    }/// <summary>
    /// 绑定第一个下拉框
    /// </summary>
    private void down1_bind()
    {
       string sql = "select * from Province";
       DataTable mytab = this.get_dt(sql);
       this.DropDownList1.DataSource = mytab;
       this.DropDownList1.DataValueField = "Provinceid";
       this.DropDownList1.DataTextField = "Provincename";
       this.DropDownList1.DataBind();
       this.DropDownList1.Attributes.Add("onchange","XmlPost(this);");
    }
    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load);}
    #endregion
    }
    }
    //**********************************数据库
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[City]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[City]
    GOif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Province]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[Province]
    GOCREATE TABLE [dbo].[City] (
    [CityID] [int] NOT NULL ,
    [CityName] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
    [ProvinceID] [int] NULL 
    ) ON [PRIMARY]
    GOCREATE TABLE [dbo].[Province] (
    [ProvinceID] [int] NOT NULL ,
    [ProvinceName] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL 
    ) ON [PRIMARY]
    GO
    //******************稍稍做了改动,测试可以用
      

  5.   

    hchxxzx(NET?摸到一点门槛) 的方法是可以的,一般都是xmlhttp来实现的,但是注意this.Response.End();有时会报异常的。
    或者是一次性读出所有数据,然后用javacsript来绑定.
    如果你的联动下拉框是 多个叶面都用到的话,最好还是 新建一个叶面来负责这个事情,
    不要post到本页。
    用个简单一点的sql语句是实现不了的。