Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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

 
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...




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





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