Currently I am working on a project that requires me to read from a .csv file and import the data into a database. Its all working fine except for just one column. In the raw/.csv file this field can consist of both int/string. So while reading the file if the first column consists of an int then any of the strings that come after wont be read. But if the first value happens to be a string then it all works as intended. Is there a solution for this that I could implement into the current working solution I have.
string sql = @"SELECT * FROM [" + strFileName + "]";
DataTable rawDataTable = new DataTable();
using (OleDbConnection connection = new OleDbConnection(connString))
using (OleDbCommand command = new OleDbCommand(sql, connection))
using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
{
adapter.Fill(rawDataTable);
}
For example, in the specific column: In the following case, when read using the code mentioned above, the datatable would show the 100 leaving the next two rows blank and then would show 500.
Sample Column
-------------
100
SOME TEXT
SOME MORE TEXT
500
But if, the column happens to be like the following sample it would work properly by reading the ints as strings.
Sample Column
--------------
100
SOME TEXT
SOME MORE TEXT
500