I read a delimited text file into dataset. i am writing these dataset values line by line in another text file. my C# syntax is :
try
{
DataClasses1DataContext db = new DataClasses1DataContext();
var r = from p in db.Products
select p;
//DataTable TarGetTable;
//TarGetTable = AddDataToTable();
String TargetStringFilePath;
TargetStringFilePath = @"c:\aaa.txt";
StreamWriter fw = File.CreateText(TargetStringFilePath);
foreach (Product drPrintRow in r)
{
//drPrintRow[drPrintRow]
String str = drPrintRow.CategoryID.ToString();
str +=" "+ drPrintRow.Discontinued.ToString();
str +=" "+ drPrintRow.ProductID.ToString();
str += " "+drPrintRow.ProductName.sToString();
fw.WriteLine(str);
}
fw.Flush();
fw.Close();
//}
}
catch (Exception ex)
{
}
I want this output in bellow format
CUSTOMERWISE ORDER STATUS REPORT
================================
Trading Date : 1-2-2010 Date :1-2-2010
Time :15:00:52
HOWLA TYPE FILL TYPE MKT TYPE ORDER STATUS
-------------- ------------------------- ----------- ---------------------------------------------
D : DVP MF : MinimumFill P : PUBLIC AC : ACTIVE CF : CompletelyFilled
N : NORMAL PF : Partial Fill S : SPOT NA : NOTACTIVE FR : FilledAndRejected
U : UNSPECIFIED FOK : FillOrKill O : ODDLOT XE : Executed EX : Expired
AON : AllOrNone B : BLOCK RJ : Rejected OM : OriginalOrderModified
PFAK : PartialFillAndKill DE : Deactivated PF : PartiallyFilled
DL : Deleted CR : CrossingReported
_______________________________________________________________________________________________________________________
CUSTOMER |INSTRUMENT| BROKER | Quantity|B | PRICE | BALANCE |HOWLA| EXPIRY | MKT|FILL|ORDER | TORN | TORN |
| | ORDER | |/ | Tk. | QTY |TYPE | DATE |TYPE|TYPE|STATUS| PREFIX | SUFFIX |
| | REFNO | |S | | | | | | | | NO | NO |
__________|__________|_________|_________|__|__________|_________|_____|__________|____|____|______|_________|_________|
00002 |BSRMSTEEL |109379297| 500|S | 1325.00| 0| N |01-02-2010| P | PF | CF |201003201| 41500123|
|CITYBANK |109379298| 200|S | 940.00| 0| N |01-02-2010| P | PF | CF |201003201| 6300609|
|POWERGRID |109379303| 500|S | 789.00| 0| N |01-02-2010| P | PF | CF |201003201| 6000269|
|SPCERAMICS|109379306| 5000|S | 93.60| 0| N |01-02-2010| P | PF | CF |201003201| 40200627|
|CITYBANK |109379439| 2000|S | 912.00| 0| N |01-02-2010| P | PF | CF |201003201| 6300918|
00004 |PREMIERBAN|109379645| 550|B | 402.75| 0| N |01-02-2010| P | PF | CF |201003201| 32601990|
|PLFSL |109379725| 100|B | 660.00| 0| N |01-02-2010| P | PF | CF |201003201| 27800430|
|MAKSONSPIN|109379373| 2000|S | 110.70| 0| N |01-02-2010| P | PF | CF |201003201| 41400304|
|MPETROLEUM|109379654| 100|S | 329.00| 100| N |01-02-2010| P | PF | AC |201003201| 36001036|
|BXPHARMA |109379867| 200|S | 185.50| 200| N |01-02-2010| P | PF | AC |201003201| 9302082|
00011 |PADMAOIL |109379692| 1000|S | 811.00| 0| N |01-02-2010| P | PF | CF |201003201| 15500272|
|MPETROLEUM|109379989| 1000|S | 324.70| 0| N |01-02-2010| P | PF | CF |201003201| 36001454|
|CONFIDCEM |109380341| 500|S | 1614.75| 0| N |01-02-2010| P | PF | CF |201003201| 6500878|
| |109380346| 500|S | 1616.00| 240| N |01-02-2010| P | PF | PF |201003201| 6500891|
| |109380351| 500|S | 1615.00| 0| N |01-02-2010| P | PF | CF |201003201| 6500905|
00012 |APEXTANRY |109379064| 100|B | 1373.50| 0| N |01-02-2010| P | PF | CF |201003201| 1300042|
| |109379154| 100|B | 1365.00| 100| N |01-02-2010| P | PF | AC |201003201| 1300127|
| |109379328| 100|B | 1385.00| 0| N |01-02-2010| P | PF | CF |201003201| 1300301|
|UNIONCAP |109379471| 500|B | 143.00| 0| N 开发者_开发百科|01-02-2010| P | PF | CF |201003201| 8000591|
| |109379535| 500|B | 143.50| 0| N |01-02-2010| P | PF | CF |201003201| 8000651|
| |109379774| 1000|B | 142.30| 0| N |01-02-2010| P | PF | CF |201003201| 8000931|
| |109380425| 500|B | 142.00| 0| N |01-02-2010| P | PF | CF |201003201| 8001532|
|PREMIERBAN|109379218| 100|S | 399.00| 0| N |01-02-2010| P | PF | CF |201003201| 32600814|
|SUMITPOWER|109380383| 100|S | 1324.00| 0| N |01-02-2010| P | PF | CF |201003201| 28401076|
| |109380438| 50|S | 1321.00| 0| N |01-02-2010| P | PF | CF |201003201| 28401129|
00013 |APEXTANRY |109379034| 100|B | 1375.00| 0| N |01-02-2010| P | PF | CF |201003201| 1300016|
How to write dataset value in text file in specified format.Is there any existing software that can do that for me.
I use Northwind database on C# syntax.HOw to write this product table information in above format.
I'd suggest starting with the string.Format method and check the additional references on the documentation page for help in determining the proper custom format strings.
I think you are looking for string.Format(...)
. This allows you to format many different data types into a defined string format.
精彩评论