0

I have an Excel file, In which i will have to parse the file in such a way that It should find the Exact sheet and In that Exact text which we are looking. then it should read the text related Checkbox whether it is checked/not. Using c# not Vba.

protected void Page_Load(object sender, EventArgs e)
{
    SearchResult();
}

private void SearchResult()
{
    try
    {
        System.Data.OleDb.OleDbConnection MyConnection;
        System.Data.DataSet DtSet;
        System.Data.OleDb.OleDbDataAdapter MyCommand;
        MyConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='\\XXX\\XXX\\XX\\Excelfiename.xlsx';Extended Properties=Excel 12.0;");
        MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [SheetName$]", MyConnection);
        MyCommand.TableMappings.Add("Table", "TestTable");
        DtSet = new System.Data.DataSet();
        MyCommand.Fill(DtSet); 
        dataGridView1.DataSource = DtSet.Tables[0];
        MyConnection.Close();
        int j = 38;
        for (int i = 0; i < DtSet.Tables[0].Rows.Count; i++)
        {
            if (DtSet.Tables[0].Rows[j].ItemArray.Contains("Result"))
            {
                if (DtSet.Tables[0].Rows[j].ItemArray.Contains("PASSED"))
                {
                    Console.WriteLine("PASSED");
                }
                else if (DtSet.Tables[0].Rows[j].ItemArray.Contains("FAILED"))
                {

                }
                else if (DtSet.Tables[0].Rows[j].ItemArray.Contains("not possible"))
                {

                }
            }
        }
    }
    catch (Exception ex)
    {

    }
}
3
  • possible duplicate stackoverflow.com/questions/7674914/… Commented Oct 8, 2016 at 6:29
  • came across that link previously, but it didnt helped in my scenario Commented Oct 8, 2016 at 6:31
  • Hello Vamsi. You’re ‘for’ loop is going to give you problems. You are checking the same row with every iteration of this loop. Do you want to loop through all the rows or just row 38 of all the tables? If you trace your example and the first if statement is true or false… it will be true/false for every iteration of the ‘for’ loop because you are checking the same row. Also checkbox type items in a table are usually Boolean types. Hope this helps. Commented Oct 9, 2016 at 0:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.