7
Answers

Filter a data from the dataset

Sairam Soham

Sairam Soham

9y
570
1
I have populated the dataset from loading the data from the spreadsheet by using the following code

  DataSet ds = new DataSet();
                ds.DataSetName = "Configurations";



                using (
                 
               OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + xlsxPath + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\""))
                {
                    try
                    {
                        using (OleDbCommand command = new OleDbCommand("select * from [Sheet1$] ", conn))
                        {
                            using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
                            {
                                try
                                {
                                    adapter.Fill(ds);
                                }
                                catch (Exception ex1)
                                {
                                    MessageBox.Show(ex1.ToString());
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
                //this can be extended in to dofferent formats since we got the data in an object.
                ds.Tables[0].TableName = "Meters";
           
                ds.WriteXml(xlsxPath.Substring(0, xlsxPath.IndexOf(".")) + ".xml")


Question:

From the attached spreadsheet, I want to filter a rows from dataset where value of column1 is 2 (Header name is MeterID)?

Any clue how shall I do it?

Will it be possible once the data get populated in the dataset, assign a column names as user friendly name?

Thanks

Answers (7)