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
biren mohanty
NA
6
0
CSV output not displaying correct format in c#
Jul 24 2014 8:26 AM
Hi,
I have some doubt regarding creating CSV files using c#
Doubt
===========
I had created simple program using Streamwritter (using c#).This is generating multiple csv files , but some field like
date
field are not displaying correct format in which the database file are showing.
Example: Database field : 10 May 2014
Csv field :10-May-20
Code:
=============
int iColCount = dtDataTablesList.Columns.Count;
int rowcount = dtDataTablesList.Rows.Count;
int loopcount = 3000;
int totalloopcount = loopcount;
int count = 1;
int remainder = rowcount % loopcount;
int Fcount = rowcount / loopcount;
string date = DateTime.Now.Date.ToString();
string datewithTime = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString();
if (remainder != 0)
{
Fcount = Fcount + 1;
}
for (int iloopcoiunt = 1; iloopcoiunt <= Fcount; iloopcoiunt++)
{
StreamWriter sw = new StreamWriter(@"E:\Biren\" + "Boxinventory" + "_" + datewithTime + "_" + iloopcoiunt + ".csv", true);
for (int i = 0; i < iColCount - 1; i++)
{
sw.Write(dtDataTablesList.Columns[i]);
if (i < iColCount - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
for (int i = count; i <= totalloopcount; i++)
{
DataRow dr = dtDataTablesList.Rows[i - 1];
for (int k = 0; k < iColCount - 1; k++)
{
if ((dr[k].ToString() != null || dr[k].ToString().Length > 0))
{
sw.Write("\"" + dr[k].ToString() + "\"");
sw.Write(dr[k].ToString());
sw.Write(",", "");
}
}
sw.Write(sw.NewLine);
count += 1;
}
totalloopcount += loopcount;
if (totalloopcount > rowcount)
totalloopcount = rowcount;
sw.Close();
}
Thanks,
Biren
Reply
Answers (
0
)
Reading XML file which is on listbox and bind data to Grid
CSV output not displaying correct format in c#