OdbcDataReader修剪前导零

时间:2016-10-27 03:30:54

标签: c# asp.net text-files datareader odbcdatareader

我正在尝试使用我的.net项目中的以下代码将txt文件读入数据库。

var ConnectionString = ConfigurationManager.ConnectionStrings[database].ConnectionString;
string strConnString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + folderPath.Trim() + ";Extensions=asc,csv,tab,txt;Persist Security Info=False;Readonly=False";
string sql_select;

OdbcConnection conn;
conn = new OdbcConnection(strConnString.Trim());
conn.Open();
OdbcCommand commandRowCount = new OdbcCommand("SELECT COUNT(*) FROM [" + fileName.Trim() + "]", conn);
sql_select = "select * from [" + file.Trim() + "]";

OdbcCommand commandSourceData = new OdbcCommand(sql_select, conn);
commandSourceData.CommandTimeout = 0;
OdbcDataReader dataReader = commandSourceData.ExecuteReader();

using (SqlBulkCopy bc = new SqlBulkCopy(ConnectionString))
{
    bc.BulkCopyTimeout = 0;
    bc.DestinationTableName = "[dbo].[" + tablename.Trim() + "]";
    bc.NotifyAfter = 5000;
    bc.BatchSize = 5000;
    bc.WriteToServer(dataReader);
    bc.Close();
}

但是OdbcDataReader正在删除其中一列(nvarchar)中的前导零。 如何保持前导零?

0 个答案:

没有答案