export to CSV

M

mcnewsxp

could i get an example of passing some SQL code to return a recordset that
gets exported to CSV.
also, same thing but populates a way to view the data before exporting.

tia much,
mcnewsxp
 
M

mcnews

Private Sub ExportDatasetToCsv(ByVal MyDataSet As DataSet)

Dim str As New StringBuilder

For Each dr As DataRow In MyDataSet.Tables(0).Rows

For Each field As Object In dr.ItemArray

str.Append(field.ToString & ",")

Next

str.Replace(",", vbNewLine, str.Length - 1, 1)

Next



Try

My.Computer.FileSystem.WriteAllText("C:\temp\testcsv.csv",
str.ToString, False)

Catch ex As Exception

MessageBox.Show("Write Error")

End Try

'Write the String to the Csv File

'myWriter.WriteLine(myString)

'Clean up
'myWriter.Close()


End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top