Hello All!
I have an excel file which I use as a data source for a dataset of mine. My C# code is as follows:
The code above works fine and I'm able to load the dataset with the data of the excel file.
The problem is this:
In one of the columns of the excel file, some cells contain strings, while other cells contain numbers. When I'm looping through the rows of the table in the dataset to get the data for this column, the cells containing text return null. I have the following code:
As I mentioned before, I only get data for the cells that contain numbers. For those that have text, data.Rows[rowIdx][colIdx].ToString() is returning an empty string. Can anyone one suggest what's happening?
The data in the column in question will always be either a number by itself, a number followed by an asterisk (*) and the letter B, or nothing at all. Some of the values in the file are:
2260
2261*B
[blank]
[blank]
2283
2284*B
I manually edited the file and removed the *B from some of these numbers, and guess what, I get the data. Put the *B back again... no data! Can anyone please shed some light?
Thanks!
JC
_________________________________________________
To get the best response to a question, read faq222-2244.
I have an excel file which I use as a data source for a dataset of mine. My C# code is as follows:
Code:
[green]// Variable declarations ommitted for clarity[/green]
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + this.RundownFile + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection cn = new OleDbConnection(connStr);
cn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + SHEET_NAME + "]", cn);
OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
ad.Fill(ds, SHEET_NAME);
The problem is this:
In one of the columns of the excel file, some cells contain strings, while other cells contain numbers. When I'm looping through the rows of the table in the dataset to get the data for this column, the cells containing text return null. I have the following code:
Code:
[green]// Variable declarations ommitted for clarity[/green]
DataTable data = ds.Tables[SHEET_NAME];
for (rowIdx=0; rowIdx<totalRows; rowIdx++)
{
[green]// for the column with the problem, this
// returns a proper value for numbers but
// it returns an empty string for the cells
// that contain strings[/green]
val = data.Rows[rowIdx][colIdx].ToString()
}
The data in the column in question will always be either a number by itself, a number followed by an asterisk (*) and the letter B, or nothing at all. Some of the values in the file are:
2260
2261*B
[blank]
[blank]
2283
2284*B
I manually edited the file and removed the *B from some of these numbers, and guess what, I get the data. Put the *B back again... no data! Can anyone please shed some light?
Thanks!
JC
_________________________________________________
To get the best response to a question, read faq222-2244.