Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 19th, 2006, 08:49 AM
Registered User
 
Join Date: Oct 2006
Location: Middlesbrough, Cleveland, United Kingdom.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exporting a Datagrid to a CSV file

Hi,

I am a new boy to programming, anyway I was wondering if anybody has any code examples of how I can export data from a DataGrid into a .csv file.

I have a single database - MS Access, and it has two tables 1094, and 1115.

Does anybody have any idea of how I can achive this.

Many thanks
pauljohns353.

:D

Reply With Quote
  #2 (permalink)  
Old November 21st, 2006, 04:56 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Here's some code to convert datagrid data to an Excel spreadsheet from an ASP.NET project I wrote:

Private Sub ConvertToExcel(ByRef r_dvReport As DataView)
    'first clean up the response.object
    Response.Clear()

    Response.Charset = ""

    'set the response mime type for excel
    Response.ContentType = "application/vnd.ms-excel"

    'create a string writer
    Dim stringWrite As New System.IO.StringWriter

    'create an htmltextwriter which uses the stringwriter
    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

    'instantiate a datagrid - used for output
    Dim dgExcelOutput As New DataGrid

    'set the output datagrid datasource to the dataset associated
    ' with the data grid being converted
    dgExcelOutput.DataSource = r_dvReport

    'bind the datagrid
    dgExcelOutput.DataBind()

    'tell the datagrid to render itself to htmltextwriter
    dgExcelOutput.RenderControl(htmlWrite)

    'all that's left is to output the html
    Response.Write(stringWrite.ToString)

    Response.End()
End Sub

hth...
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting a csv file (comma separated) micharl Beginning VB 6 6 May 7th, 2008 10:10 PM
Exporting a DataGrid to a CSV - VB.net pauljohns353 Visual Studio 2005 0 October 19th, 2006 08:46 AM
Exporting to CSV smajumdar_82 Access VBA 1 July 10th, 2006 10:38 AM
Need help in exporting memo fields to CSV file Programming_starter C# 0 May 22nd, 2006 11:25 AM
Exporting Data from DataGrid to a CSV file PT ASP.NET 1.0 and 1.1 Professional 2 June 22nd, 2005 04:41 AM



All times are GMT -4. The time now is 09:25 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.