2013-05-30 39 views
0

我正在從數據庫中讀取數據以寫入二進制文件並使用Sybase的bcp命令將大數據一次寫入新數據庫(或千等千)整數不能寫成正確形式的字符串到二進制文件

你可以看到我的實體IdNumbers是整數,我正在寫它作爲一個字符串文件。

enter image description here

但在二進制文件中的數據是這樣的:

F1,LS-CIC,12日,1999-00-12,2070-00-01,1999-00 -12,jdefinis,0,...,N,0,0112,000,0,0,000,0,0,0,0,0,0,...,ALL d2,LS-CIC,12, ,1999-00-12,2070-00-01,1999-00-12,jdefinis,0,N,0,0112,,, 0 ,,,0,0,0,0,0,0,0 ,,,,全部 d3,LS-CIC,12,1999-00-12,2070-00-01,1999-00-12,jdefinis,0,N,0,0112,L1,0,...,L1,0,0, 0,0,0,0,,,, ALL d4,LS-CIC,12,,1999-00-12,2070-00-01,1999-00-12,jdefinis,0,,N, 0,0112,L2,0,...,L2,0,0,0,,0,0,0,,,, ALL d5,LS-CIC,12,,1999-00-12,2070-00 -01,1999-00-12,jdefinis,0,,N,0,0112,L3,0,...,L3,0,0,0,,0,0,0,,,, ALL

每個數字「4」在二進制文件中被轉換爲「d4」。爲什麼?我該如何糾正這個問題?

回答

0

BinaryWriter將一些額外的數據信息(如長度)放入文件中。如果您想將文件寫入文本,請改用StreamWriter。參見前,

using (var f = File.Create(filename)) 
{ 
    BinaryWriter bw = new BinaryWriter(f); 
    bw.Write(String.Join(",", Enumerable.Range(0, 37))); 
} 

如果預計產量將0,1,.....,36號這將是

d0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36

PS:d是ASCII 100這是字符串的長度0,1,...,36

0

我將BinaryWriter更改爲StreamWriter以防止出現問題。在二進制形式總是額外的字符與文件隨着I4V說

+0

這是如何stackoverflow工作:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – I4V

相關問題