I have a Application on which i'm uploading a Excel File and displaying the data inside a GridView. My problems is now that, When I'm uploading the File gets uploaded. If the Data contains a MIX of Intergers and Text data, Text data's are not shown inside the Gridview and the DataSet on which im loading it.
public DataTable GetExcelData(string _FileName)
{
DataSet ds = new DataSet();
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _FileName + ";Extended Properties=Excel 8.0;";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
string sheetname = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["table_name"].ToString();
try
{
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [" + sheetname + "]", connection);
adapter.Fill(ds);
connection.Close();
return ds.Tables[0]; ;
}
catch (Exception ex)
{
try
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
catch (Exception) { }
throw ex;
}
}
This is code from which i'm loading the data onto the DataSet.
Ill show you an Example data
Column1
- 1234
- 2345
- 4567
- T123
- 123Q
- 6789
If we upload an Excel sheet with the Data Above it will only display it like this..
Column1
- 1234
- 2345
- 4567
- .
- .
- 6789
You can see in the Above T123,123Q is missing(it will be BLANK data). This is the Problem with my application when i'm Uploading an Excel sheet.
Has anyone come across a situation like this? Is there any way we can resolve this?