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
narasiman rao
NA
519
767.1k
how to add header name in console application in excel
Aug 26 2016 10:10 AM
My code as follows
string connectionString = ConfigurationManager.ConnectionStrings["Connectionstring"].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "select * from customers";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection;
sqlConnection.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
using (System.IO.StreamWriter fileOutput = new System.IO.StreamWriter(@"C:\Users\551386\Desktop\DataDump\ "Excel.xls"))
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
fileOutput.AutoFlush = true;
fileOutput.Write(reader[i].ToString() + "\t");
}
}
fileOutput.Write("\n");
}
}
sqlConnection.Close();
}
when i write the above and run in excel data will be download as follows
1 suresh 988789899 chennai IN 1
2 rajeshr 988788799 chennai IN 2
3 mootrhi 988787699 chennai Out 3
select * from customers records as follows
id Name Mobile Place Type Cityid
1 suresh 988789899 chennai IN 1
2 rajeshr 988788799 chennai IN 2
3 mootrhi 988787699 chennai Out 3
but in excel the above column name is not coming in excel when i download.
id Name Mobile Place Type Cityid
the above column name is not showing in excel when i download.
what is the mistake in my above code.
Reply
Answers (
1
)
listview data search shows repeatedly .
Replace a string in text file with a 2D array