Subject: Dataset Problem
Posted By: monika.vasvani Post Date: 9/23/2006 2:08:05 AM
HI Every1

I have created a DataSet object and loaded few tables into it (they come from different data sources). As there are relations between them, I also created appropriate Relations objects.
Now I would like to extract some data based on certain criteria. In other words, is it possible to run a SELECT statement against a DataSet object? (Or any other way how to extract desired data from this object?)

Thanx
monika

Reply By: mike_remember Reply Date: 9/26/2006 10:04:10 AM
Yes Monika

That is possible, but in case of DataView. But no need to worry, you can easily convert the DataSet to DataView and then use the RowFilter property of DataView, code example is below:

private void BindGrid()
        {
            SqlConnection sConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            string sQuery = "select * from TestTable";
            SqlDataAdapter da = new SqlDataAdapter(sQuery,sConn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            
//HERE WE CONVERT DATASET TO DATAVIEW
            ds.Tables[0].DefaultView.RowFilter = "ProjectID = '1'";

//AND BIND THE GRID WITH TABLE[0]'S VIEW
            dg.DataSource = ds.Tables[0].DefaultView;
            dg.DataBind();
        }


Regards
Mike

Go to topic 50102

Return to index page 164
Return to index page 163
Return to index page 162
Return to index page 161
Return to index page 160
Return to index page 159
Return to index page 158
Return to index page 157
Return to index page 156
Return to index page 155