Hi,
I got one more problem with importing csv files using .net. The problem is that the csv file contains double-quotation marks (""). For example, the record looks like:
...,Bearing Double "D" Flange,...
And the result is: ... | Bearing Double | null (all following columns are null)
The code is as following:
string strCsvConn =@."Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\;Extended Properties='text;HDR=Yes;FMT=Delimited(,)';";
using (OleDbConnection cn =newOleDbConnection(strCsvConn))
{
string strSQL ="SELECT * FROM " + strFileName;
OleDbCommand cmd =newOleDbCommand(strSQL, cn);
cn.Open();
using (OleDbDataReader dr = cmd.ExecuteReader())
{
while (dr.Read()){
string str =Convert.ToString(dr[8]);
}
// Bulk Copy to SQL Server
//using (SqlBulkCopy bulkCopy = new SqlBulkCopy(strSqlConn))
//{
// bulkCopy.DestinationTableName = strSqlTable;
// bulkCopy.WriteToServer(dr);
//}
}
}
Any idea is highly appreciated.
shz
Hello shz,
I would recomend using a TextReader for processing a .csv file.
Hope this helps
regards,
G
|||Thanks Gonzo. However, TextReader should be the last thing I'd like to use.
shz
sql
No comments:
Post a Comment