vipin katiyar
vipin katiyar

Reputation: 3547

How to search a string in a column of an Excel file

I have an excel file which have a column name (name) which has the following entries:

  1. vipin
  2. vipin
  3. vipin
  4. vipin

I want to count the entries in the name column where my string is "vipin". Using OLEDB data provider.

Upvotes: 0

Views: 2379

Answers (1)

Kenoyer130
Kenoyer130

Reputation: 7308

Are you pulling the excel sheet into a DataTable like so?

OleDbDataAdapter cmd = new System.Data.OleDb.OleDbDataAdapter(   
            "select * from [" + worksheetName + "$]", con);   

        con.Open();   
        System.Data.DataSet excelDataSet = new DataSet();   
        cmd.Fill(excelDataSet);   
        con.Close();  

If so just iterate through the DataRows like normal.

foreach(DataRow dataRow in excelDataSet.Tables[0].Rows){
    if(dataRow["columnName"].ToString().Equals("vipin")){
       count++;
    }
}

Upvotes: 2

Related Questions