我有一个表,一个列是宿舍的,如:07315。其他列是别的信息,我想把这一列所有是07开头的行都选出来存在dataset中,再将073开头的选出来显示在dataset中,如何写代码。
注:数据库是sql2005,最好用C#写

解决方案 »

  1.   

    select * from table where columname like '07%'
      

  2.   

    select * from tablename where columnname like '07%'
      

  3.   


    select dormitoryColumn from tableName where dormitoryColumn like '07%'
    //查找宿舍列以07开头的信息
      

  4.   

    楼主没必要放到两个DataSet当中,查找出来放到一个DataSet里,之后检索不同的数据即可。
      

  5.   

    select * from tablename where columnname like '07%'
    select * from tablename where columnname like '073%'
      

  6.   

    create table a(
    ssid nvarchar(20)
    )insert into a
    select('12115') union all
    select('0717') union all
    select('1216') union all
    select('07317') union all
    select('07553') union all
    select('076') union all
    select('07')DataSet ds = new DataSet();
    using (SqlConnection conn = new SqlConnection("server=.;user id=sa;password=;database=testDb;"))
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "select * from a where ssid like '07%'";
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = cmd;
        adapter.Fill(ds);
    }//以07开头的结果集为基础,进一步筛选
    DataView dv =new DataView();
    dv.Table = ds.Tables[0];
    dv.RowFilter = "ssid like '073%'";//打印 07开头的结果集
    GridView1.DataSource = ds.Tables[0];
    GridView1.DataBind();//打印 073开头的结果集
    GridView2.DataSource = dv;
    GridView2.DataBind();