问一个简单的程序
用c#做个窗体
一个文本框,一个按钮,一个dategride
数据库中表table有个字段title
我在文本框中输入字符,点击按钮,下面那个dategride中就列出table中的所有字段
select * from table where title like '%文本框%'该怎么写啊?
小弟初学.net啊!还什么都不懂啊!
各位高手帮帮忙,指教一下啊!
谢了啊!

解决方案 »

  1.   

    数据库连接语句就不写了
    SqlCommand cmd = new SqlCommand("select * from table where title like '%+txt.text+"%'",连接)
    sqldatareader dr=cmd.ExecuteReader(CommandBehavior.CloseConnection);
    然后datetrid榜定dr就可以了
      

  2.   

    datalist绑title autopostback=truedatagrid 绑%datalist.dataitem%
      

  3.   

    SqlCommand cmd = new SqlCommand("select * from table where title like '%+txt.text+"%'",连接)
    sqldatareader dr=cmd.ExecuteReader(CommandBehavior.CloseConnection);
    datagrid.datasource=dr;
      

  4.   

    每按一下按钮,重新绑定datagrid
      

  5.   

    单击按钮时把获取文本字段放到SqlCommand中,( select * from table where title like '%+txt.text+"%'),然后重新读取数据绑定数据
      

  6.   

    //如果是Sqlserver,引入命名空间
    using System.Data.SqlClient;//输入字符串后,点击按钮下的代码,模仿一下:
    SqlConnection con = new SqlConnection("server=.;database=student;uid=sa;pwd=0421");
                try
                {
                    SqlCommand cmd = new SqlCommand("select * from studentInfor where sno like '%"+this.textBox1 .Text +"%'", con);
                    SqlDataAdapter sda = new SqlDataAdapter();
                    sda.SelectCommand = cmd;
                    DataSet ds = new DataSet();
                    sda.Fill(ds, "student");
                    this.dataGridView1.DataSource = ds.Tables["student"];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message );
                }
      

  7.   

    datagrid.datasource=ds;
    datagrid.Bind();
      

  8.   

    //如果是Sqlserver,引入命名空间
    using System.Data.SqlClient;//输入字符串后,点击按钮下的代码,模仿一下:
    //说明一下:以下student是数据库名,uid用户名,pwd为密码
    SqlConnection con = new SqlConnection("server=.;database=student;uid=sa;pwd=0421");
                try
                {
            //studentInfor是表名,sno是列名
                    SqlCommand cmd = new SqlCommand("select * from studentInfor where sno like '%"+this.textBox1 .Text +"%'", con);
                    SqlDataAdapter sda = new SqlDataAdapter();
                    sda.SelectCommand = cmd;
                    DataSet ds = new DataSet();
                    sda.Fill(ds, "student");
            //vs2005下dataGridView,vs2003下用dataGrid
                    this.dataGridView1.DataSource = ds.Tables["student"];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message );
                }