Hi vygi0913,
Here i have created sample that full fill your requirement. You can refer the below article to read the data from excel to dataset.
Code
private void btnGetCount_Click(object sender, EventArgs e)
{
string strExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
+ @"D:\Test.xls"
+ "; Extended Properties='Excel 8.0;HDR=Yes'";
OleDbConnection connExcel = new OleDbConnection(strExcelConn);
OleDbCommand cmdExcel = new OleDbCommand();
OleDbDataAdapter da = new OleDbDataAdapter();
cmdExcel.Connection = connExcel;
connExcel.Open();
DataTable dtExcelSchema;
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
connExcel.Close();
DataSet ds = new DataSet();
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
da.SelectCommand = cmdExcel;
da.Fill(ds);
string nonEmptyCell = string.Empty;
for (int row = 0; row < ds.Tables[0].Rows.Count; row++)
{
string tcNo = ds.Tables[0].Rows[row].ItemArray[0].ToString();
int count = 0;
for (int column = 1; column < ds.Tables[0].Rows[row].ItemArray.Length; column++)
{
string value = ds.Tables[0].Rows[row][column].ToString();
if (!string.IsNullOrEmpty(value))
{
count++;
}
}
nonEmptyCell += "TC NO " + tcNo + " has " + count + " non empty cells. \n";
}
lblCount.Text = nonEmptyCell;
}
Screenshot
