TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sumit Kumawat
NA
454
415.9k
How to wrap text value of datatable row's in C#?
Sep 28 2017 5:01 AM
Hi all,
I am exporting my DataTable values to .txt file using code and its working fine.
i want to wrap text data of Rows value so that it can will look good.
means i want to display it in proper manner.
below is my ouput
ID | Name | Address
1 | VenkVenkVenkVenkVenkVenkVe | chennai
2 | Hanu | London
3 | john | Swiss
i want to wrap data of name Column
i want to output like this :
ID | Name | Address
1 | VenkVenkVenk
VenkVenkVenkVe | chennai
2 | Hanu | London
3 | john
| Swiss
Below is my code
private void CreateDT()
{
DataTable dt = new DataTable();
//Adding data To DataTable
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Address");
dt.Rows.Add(1, "VenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenk", "chennai");
dt.Rows.Add(2, "Hanu", "London");
dt.Rows.Add(3, "john", "Swiss");
// DataGridView grid = new DataGridView();
int i = 0;
StreamWriter swExtLogFile = new StreamWriter("D:/DTlog2.txt", true);
//StreamWriter sw = null;
// sw = new StreamWriter(submittedFilePath, false);
for (i = 0; i < dt.Columns.Count - 1; i++)
{
swExtLogFile.Write(dt.Columns[i].ColumnName + "\t" +"\t" + " | ");
}
swExtLogFile.Write(dt.Columns[i].ColumnName);
swExtLogFile.WriteLine();
foreach (DataRow row in dt.Rows)
{
object[] array = row.ItemArray;
for (i = 0; i < array.Length - 1; i++)
{
swExtLogFile.Write(array[i].ToString() + "\t" + "\t" + " | ");
}
swExtLogFile.Write(array[i].ToString());
swExtLogFile.WriteLine();
}
swExtLogFile.Close();
}
Reply
Answers (
1
)
Keydown Event not working properly
How to print 3 copy of Invoice from crystal report?