Link to home
Start Free TrialLog in
Avatar of jj819430
jj819430

asked on

Excel Empty Cell Value

I am reading in from and excel sheet, and placing into a string.
we shall say
ExcelString = (data from excel).

Does anyone know what the value of ExcelString is if the cell was empty?
I need this for comparison, and it is in a place in the app I can't even have it output it to the screen.
I know it is not "null"
I know it is not an empty string ""
 
ASKER CERTIFIED SOLUTION
Avatar of testn
testn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jj819430
jj819430

ASKER

I am trying to use it in an if statement.

if (ExcelString != DBNull.Value)
{
}
is not capturing it... it is weird because I would have thought it would be fine.
I meant

if(ExcelString != Convert.ToString(DBNull.Value))
{
}
Can you put more code?

How do you connect to excel? Using COM object or OLEDB?
void ConnectandRead()
{
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\Files\\" + filename + ";" +"Extended Properties='Excel 8.0; IMEX=1;'";
                  
                  
                  OleDbConnection objConn = new OleDbConnection(sConnectionString);

                  
                  objConn.Open();

                  OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1, "XLData");

}

After this reading of the data, I put it in a datagrid for display and editing. I convert each one into string format (by force) in order to work with another neccessary

So I have it as string ExcelString = DataGridExcel.Items[1].Cells[0].Text

I am trying to figure out what is in ExcelString if the data read from the excel sheet was a null.
Nevermind, got it on my own. It was == " " (I guess it changes it to a black space if it is null during the conversions.