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
771.8k
how to save database record in to excel using C#
Aug 15 2016 10:27 AM
My code as follows
string str = "Server=(local);initial catalog=testingdb;Trusted_Connection=True";
SqlConnection objConn = new SqlConnection(str);
objConn.Open();
SqlDataAdapter daAuthors = new SqlDataAdapter("Select * From Empdetails", objConn);
DataSet dsPubs = new DataSet("Pubs");
daAuthors.FillSchema(dsPubs, SchemaType.Source, "Empdetails");
daAuthors.Fill(dsPubs,"Empdetails");
DataTable tblAuthors;
tblAuthors = dsPubs.Tables"Empdetails"];
foreach (DataRow drCurrent in tblAuthors.Rows)
{
Console.WriteLine("{0} {1} {2} {3} {4} {5} {6}",
drCurrent["ID"].ToString(),
drCurrent["Name"].ToString(),
drCurrent["Address"].ToString(),
drCurrent["City"].ToString(),
drCurrent["Mobile"].ToString(),
drCurrent["Actvie"].ToString(),
drCurrent["Type"].ToString());
}
When i execute the above code in command prompt output as follows
ID Name Address City Mobile Actvie Type
1 Ramya Road Kochi 9840575350 A 1
2 Giriesh Nagar Kochi 9745554689 A 1
3 Vimal BoagRoad Kochi 9645777566 A 1
But i want the above database record to be save in excel,
how to save the above database record into excel.
Reply
Answers (
5
)
Displaying the database record in to Gridview using conditio
how to write C# code from vbScript