我建了个数据库,用C#连接上了,现在想实现简单的在TEXTBOX里输入值,按BUTTON进行查询,然后返回所需要的行,请各位江湖仁人志士帮帮忙,能留下QQ的最好,时间紧迫!感激不尽!!

解决方案 »

  1.   

    补充说明,我用DATASET访问表,DATAGRIDVIEW显示返回的信息。
    我想在textbox里输入姓名,然后查询表中的“姓名”列,符合的就输出就行了,请帮我写出代码即可。
    表有50行。
      

  2.   

    需要两页  一页提交查询 一页显示结果总的原则是将 select * from ** where ** 语句分开 来查询一般情况使用  switch()  {case break;case break;...... default break;}  来判断查询类型,textbox里面的值使用类似 and **  like '%"+ this.TextBox1.Text +"%' "; 这样的语句判断  到显示页面后 组成一组完整的查询语句 来显示就可以了.
    也不知道对你有没有帮助..   :)
      

  3.   

    //库名DBCheck
    //表名users
    string search = TextBox1.Text.Trim();
    SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
    string sql = "select name from users where name like'%"+search+"%'";
    SqlDataAdapter adap = new SqlDataAdapter(sql,conn);
    DataSet ds = new DataSet();
    adap.Fill(ds);
    if(ds.Tables[0].Rows.Count > 0)
    {
      //返回所要的记录
      //GridView1.DataSource = ds.Tables[0].DefaultView;
    }
      

  4.   

    哥们你可以这样:
    string selectSql="select * from table where";
    if(this.textBox.text!="")
    {
        selectSql+="name='"+textBox.text.Trim().ToString()+"'";
    }
    else
    {
        MessageBox.Show("请输入正确的查询条件!","提示消息",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
    try
    {
        using(conn= new  OracleConnection(Connection.localConnectString))
        {
                        ds = new DataSet();
                        da = new OracleDataAdapter(selectSql, conn);
                        da.Fill(ds, "tableName");
                        dataGridView.AutoGenerateColumns = true;
                        dataGridView.DataSource = ds;
                        dataGridView.DataMember = "tableName";
        }
    }
    catch(Exception ex)
    {
        MessagerBox.Show(ex.Message);
    }
    如果表中的列不要全部显示的话,那你可以这样写:
    dataGridView.Columns[“列名”].Visible=false;
    要是用的其他数据库把上边的dataadapter该下。
      

  5.   

    好象dataset有个filter 属性
    还是dataset.table有个filter属性dataset.filter = "列名 = '" + 条件 +"'";
      

  6.   

    对不起,刚才看了哈,是bindingSource的Filter 属性
    如果你用了bindingSource的话.
    如:bindingSource.Filter = "username = ' " + textbox.text + " ' ";
      

  7.   

    如果你用了bindingSource的话. 
    如:bindingSource.Filter   =   "username   =   '   "   +   textbox.text   +   "   '   ";这里出现错误。
    :((System.ComponentModel.ISupportInitialize)(this.enterprise_DataDataSet)).EndInit();
      

  8.   

              DataRow[] rows = this.dbCenter.busDt.Select("MyBusId like '" + this.textBox1.Text+ "%'");            this.listView1.Items.Clear();
                foreach (DataRow row in rows)
                {
                    ListViewItem newItem = new ListViewItem();
                    newItem.SubItems[0].Text = row["MyBusId"].ToString();
                    newItem.SubItems.Add(row["MyBusType"].ToString());                this.listView1.Items.Add(newItem);
                }
      

  9.   

    在button里面加入SQL语句就可解决·
      

  10.   

    一句话 
    用SqlDataReader能解决这个问题 
      

  11.   

    dahai99007 
     
    等 级:
     发表于:2008-01-02 17:41:076楼 得分:0 
    哥们你可以这样: 
    string   selectSql="select   *   from   table   where"; 
    if(this.textBox.text!="") 

            selectSql+="name='"+textBox.text.Trim().ToString()+"'"; 

    else 

            MessageBox.Show("请输入正确的查询条件!","提示消息",MessageBoxButtons.OK,MessageBoxIcon.Information); 

    try 

            using(conn=   new     OracleConnection(Connection.localConnectString)) 
            { 
                                            ds   =   new   DataSet(); 
                                            da   =   new   OracleDataAdapter(selectSql,   conn); 
                                            da.Fill(ds,   "tableName"); 
                                            dataGridView.AutoGenerateColumns   =   true; 
                                            dataGridView.DataSource   =   ds; 
                                            dataGridView.DataMember   =   "tableName"; 
            } 

    catch(Exception   ex) 

            MessagerBox.Show(ex.Message); 

    如果表中的列不要全部显示的话,那你可以这样写: 
    dataGridView.Columns[“列名”].Visible=false; 
    要是用的其他数据库把上边的dataadapter该下。 
     
     
    照着模仿一下就好了!