Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear all

I am fetching some data from database having 4 columns

I want to fetch it in notepad file by creating same no of columns as follows

I also want set its width of fix size

colmn1          column2              column3             column4
------         ---------                -------          ---------
------         ---------               --------          --------

------         --------                 --------         ----------
Posted
Updated 30-Nov-11 19:54pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Dec-11 2:31am    
Not a question. Also, what do you call "notepad file"? There is no such thing.
--SA
mayur csharp G 1-Dec-11 3:44am    
.txt file

1 solution

If you mean a file that notepad can read, then you mean a text file: i.e. a file with teh extension ".TXT"
.TXT does not have a concept of fixed widths, so if you want to lay out the file content then you need to write to teh file in a structured manner. Fortunately, .NET provides string.Format which can do this, as well as the format string parameter to teh Write and WriteLine methods.
What you need to provide in the format string is the complete fixed width format that you want to output - which will vary depending on your data types.
For example, if you want to output an int "i" and a string "s" as fixed format data:

C#
int i = 12;
string s = "ABC";
myStream.WriteLine("{0,6}  {1,10}", i, s);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900