Export:
Public voidExporttxt () {varFile = System.IO.File.Open (Path, System.IO.FileMode.Open); using(varstream =NewSystem.IO.StreamReader (file)) { while(!Stream. Endofstream) {string[] Qwe = stream. ReadLine (). Split (','); stringsql =string. Format ("INSERT into table values (' {0} ', ' {1} ', ' {2} ', ' {3} ', ' {4} ', ' { 5} ', ' {6} ', ' {7} ')", qwe[0], qwe[1], qwe[2], qwe[3], qwe[4], qwe[5], qwe[6], qwe[7]); }} file. Close (); }
Import:
Public voidwritetxt () {System.IO.FileStream fs=NewSystem.IO.FileStream (Path, System.IO.FileMode.Create); //get byte arraySystem.Data.DataTable dt = handle. ExecuteDataset ("select * FROM table"). tables[0]; for(inti =0; i < dt. Rows.Count; i++) { for(intx =0; x < dt. Columns.count; X + +) { byte[] WR; if(x! = dt. Columns.count-1) {WR=NewUTF8Encoding (true). GetBytes (dt. ROWS[I][X]. ToString () +","); } Else{WR=NewUTF8Encoding (true). GetBytes (dt. ROWS[I][X]. ToString () +"\ r \ n"); }
byte array, byte offset, maximum number of bytes written
0// clear buffer, close stream fs. Flush (); Fs. Close (); }
C # Database Export (in) TXT