Skip to content

Hi, I am very new to C#, I have to create an application that reads data from excel and checks if an...

shuba rani

Asked Jun 24, 2012, 7:59 AM EDT2 answers
Share
LinkedInX
Hi,
I am very new to C#, I have to create an application that reads data from excel and checks if any cell in excel is empty.

I have imported the excel contents onto DataGridView.Now i want to check if any cell is empty. Please help in completing this code
Please find the code so far.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Excel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\V12.xlsx" + @";Extended Properties=""Excel 12.0;HDR=Yes;ImportMixedTypes=Text;TypeGuessRows=0""";
            OleDbCommand Command = new OleDbCommand
            ("SELECT* FROM [Sheet1$]", conn);
            DataSet dsIDs = new DataSet();
            OleDbDataAdapter adapter = new OleDbDataAdapter(Command);
            adapter.Fill(dsIDs);
            dataGridView1.DataSource = dsIDs.Tables[0];

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0
    Welcome to C# Corner subha. Please keep your question title short. For example, for this post, your title of the question should be 

    "Check if any Excel cell is empty in C#"


    0
  • Suthish Nair
    0
    you can loop all the table rows and check each cells for blank/null.
    0