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
supriya nikam
1.6k
86
4.3k
trying to write to a csvfile from a data set
Feb 13 2021 11:31 AM
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Build the CSV file data as a Comma separated string.
Dim csv As String = String.Empty
'Add the Header row for CSV file.
For Each column As DataGridViewColumn In dataGridView1.Columns
csv += column.HeaderText & ","c
Next
'Add new line.
csv += vbCr & vbLf
'Adding the Rows
For Each row As DataGridViewRow In dataGridView1.Rows
For Each cell As DataGridViewCell In row.Cells
'Add the Data rows.
csv += cell.Value.ToString().Replace(",", ";") & ","c
Next
'Add new line.
csv += vbCr & vbLf
Next
'Exporting to Excel
Dim folderPath As String = "C:\CSV\"
File.WriteAllText(folderPath & "DataGridViewExport.csv", csv)
End Sub
Reply
Answers (
2
)
Calling WEB API to download excel file
how to do tcp/ip programming with c#