?
Solved

Export dataset to CSV

Posted on 2003-03-12
3
Medium Priority
?
2,764 Views
Last Modified: 2012-05-04
Hi,

I need to create a CSV file from SQL Server data from an ASP.NET or VB.NET application to mailmerge with MS Word.

I can populate a dataset from SQL Server and write to XML but MS Word can't use XML as a data source - damn!

Anyone got any ideas - other than cycling through the dataset and manually creating the text csv file?

Hopeful,
Steve
0
Comment
Question by:stevenhollidge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 300 total points
ID: 8119690
Dim myTable As DataTable
Dim myRow As DataRow
Dim numCols As Integer = 0
Dim myString As String
Dim myWriter As New System.IO.StreamWriter("firstCSV.csv")

For Each myTable In DataSet1.Tables
For Each myRow In myTable.Rows
myString = "" For numCols = 0 To myTable.Columns.Count - 2
If Object.ReferenceEquals(myRow.Item(numCols).GetType(), myString.GetType()) Then
myString = myString & """" & myRow.Item(numCols).ToString() & ""","
ElseIf Object.ReferenceEquals(myRow.Item(numCols).GetType(), numCols.GetType()) Then
myString = myString & myRow.Item(numCols).ToString() & ","
End If

Next
If Object.ReferenceEquals(myRow.Item(numCols).GetType(), myString.GetType()) Then
myString = myString & """" & myRow.Item(numCols).ToString() & """"
ElseIf Object.ReferenceEquals(myRow.Item(numCols).GetType(), numCols.GetType()) Then
myString = myString & myRow.Item(numCols).ToString()
End If
myWriter.WriteLine(myString)
Next

Next
myWriter.Close()
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9671380
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by iboutchkine

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question