在DropDownList中选择查询条件,然后单击查询按钮,在GridView中显示符合条件的数据。注:我用的是VS2008+SQL2005,连接数据库的方法是 LINQ to SQL 类,不需要写连接数据库语句的那种

解决方案 »

  1.   

    LINQ语法不会,给LZ个思路,根据选择的内容拼接条件查询,重新绑定数据即可
      

  2.   

    var retProducts=from p in dataContext.Products where p.Price>10 select p;
    gv.DataSource=retProducts;
    gv.DataBind();
      

  3.   

    var p= from c in ctx.User
    where c.Country == ""                   
    select p;
    db.ExecuteCommand("");
      

  4.   

            protected DataClasses1DataContext dc;
            protected BindingSource bind;
              
          private void 下载绑定数据按钮_Click(object sender, TreeNodeMouseClickEventArgs e)
            {
                  //表的名字是zidian,有个字段leibie
                dc = new DataClasses1DataContext();
                var WAF_pihao = from a in dc.zidian
                                where a.leibie == “xxx"
                                select a;
                bind = new BindingSource();//看你是否需要
                bind.DataSource = WAF_pihao;//看你是否需要
                bindingNavigator1.BindingSource = bind;//看你是否需要
                dataGridView1.DataSource = bind;
                this.dataGridView1.Columns[1].HeaderText = "  备    注";//看你是否需要
                this.dataGridView1.Columns[2].Visible = false;//看你是否需要
               }
    ===========================
    如果你有使用protected BindingSource bind;
               
                bind = new BindingSource();//看你是否需要
                bind.DataSource = WAF_pihao;//看你是否需要
                bindingNavigator1.BindingSource = bind;//看你是否需要
    的话,你可以在按钮中用 ,bind.MoveNext;跳下一记录  ,bind.AddingNew增加新记录等等编辑功能 
      

  5.   

    来个最简单版本,看不懂的话
    protected DataClasses1DataContext dc;
      private void 下载绑定数据按钮_Click(object sender, TreeNodeMouseClickEventArgs e)
      {
      //表的名字是zidian,有个字段leibie
      dc = new DataClasses1DataContext();
     
      dataGridView1.DataSource = from a in dc.zidian where a.leibie == “xxx" select a;
       }
    where a. 后面是条件,你自己改下就成了
      

  6.   

     this.dataGridView1.GridColor = Color.Brown; string MySQL = "select * from rooms Where [distinct]='" + this.comboBox1.Text+ " ' ";
                    
     DataTable MyTable = new DataTable();
     SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, db1.sqlConnection1);
     MyAdapter.Fill(MyTable);
     this.dataGridView1.DataSource = MyTable;
     MyAdapter.Dispose();