0

I'm reading data from a database to write to a binary file and using the bcp command of Sybase to write big data to my new database in one go (or thousand by thousand etc.)

You can see my entity IdNumbers are integer and I'm writing it to file as a string.

enter image description here

But in binary file data is like this:

f1,LS-CIC,12,,1999-00-12,2070-00-01,1999-00-12,jdefinis,0,,N,0,0112,000,,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, ,,,ALL 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

Each number "4" is converted to "d4" in binary file. Why? And how can I correct this problem?

John Willemse
  • 6,608
  • 7
  • 31
  • 45
htcdmrl
  • 194
  • 1
  • 10

2 Answers2

0

BinaryWriter puts some extra info about the data (such as length), into the file. If you want to write the file as text, use StreamWriter instead. See for ex,

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

if you expect the output will be 0,1,.....,36, No. It will be

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 is 100 in ASCII which is the length of the string 0,1,...,36

I4V
  • 34,891
  • 6
  • 67
  • 79
0

I changed the BinaryWriter to StreamWriter for preventing the problem. In binary form always extra characters are coming with file as I4V says

htcdmrl
  • 194
  • 1
  • 10