Solved

New to ASP.NET VB - Issue with export filtered datagrid to Excel

Posted on 2003-10-23
12
233 Views
Last Modified: 2010-04-17
Good Afternoon,

I am trying to define a button which will export the filtered results of a datagrid to Excel.  

Below is the code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As        
        System.EventArgs)    Handles btnExport.Click
       
        Dim sSQL As String

        Call BuildSelectEquipInvSQL(sSQL)

        sqlconCTXControl.Open()

        Response.ContentType = "application/vnd.ms-excel"
        Response.Charset = ""
        dgrdEquipInv.DataSource = dstEquipInv.Tables("EquipInv").Select(sSQL)
        dgrdEquipInv.DataBind()

        sqlconCTXControl.Close()
    End Sub

The data resides in a SQL database.

When debugging, I receive the following error:

Server Error in '/mimsearch' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 644:        Response.ContentType = "application/vnd.ms-excel"
Line 645:        Response.Charset = ""
Line 646:        dgrdEquipInv.DataSource = dstEquipInv.Tables("EquipInv").Select(sSQL)
Line 647:        dgrdEquipInv.DataBind()

Both the datagrid and dataset are defined as follows:
    Protected WithEvents dgrdEquipInv As System.Web.UI.WebControls.DataGrid
    Protected WithEvents dstEquipInv As System.Data.DataSet

I am looking for the correct code to properly export the filtered datagrid to an Excel spreadsheet, preferable bringing up the 'Save-As' dialog box for the user to select the destination.  The server does not have Excel installed on it which will require saving the file as a *.csv.

Thank you for your help,
Erik

0
Comment
Question by:customertrax
[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
12 Comments
 
LVL 19

Expert Comment

by:Desp
ID: 9609400
0
 
LVL 4

Expert Comment

by:Sandeepk1999
ID: 9617756
Looks like your sqlconCTXControl is not set.

Set sqlConCTXControl = New ...........
sqlConCTXControl.open()
....

0
 
LVL 19

Expert Comment

by:Desp
ID: 10319268
Recommendation: Points to Desp
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 19

Expert Comment

by:Desp
ID: 10329909
As the timeperiod was so long so the recommendation is PAQ/Not Refund
0
 
LVL 1

Author Comment

by:customertrax
ID: 10333341
The time period is irrelevant.  None of the posted responses provided a solution.  Therefore, no points should be awarded, and the points should be refunded.  I found my answer on a spanish website which was not provided by any response.
0
 
LVL 1

Author Comment

by:customertrax
ID: 10333342
The time period is irrelevant.  None of the posted responses provided a solution.  Therefore, no points should be awarded, and the points should be refunded.  I found my answer on a spanish website which was not provided by any response.
0
 
LVL 19

Expert Comment

by:Desp
ID: 10339597
If none of the posted responses provided a solution you should have posted a comment back here...
Time period is not irrelevent... please study the guidelines
http:help.jsp#hi51
It says:

Stay active in your question:  
We shouldn't have to say this after suggesting that you communicate, but we'll repeat it. People are taking the time to answer your question; the least you can do, even if it's out of just courtesy, is to respond to their suggestions, and to report the results. It should also go without saying that you should close your questions.  

And i am not asking for points now... I just want the moderators to not refund you the points..
0
 
LVL 1

Author Comment

by:customertrax
ID: 10343338
Please keep all spiteful comments out of this discussion.  The facts are none of the postings provided a solution, and I found the solution on a spanish website.  I apologize for my lack of response, but there was minimal 'activity' your response, only two links.  If you would like to discuss this personally, I would be happy to provide my contact information so we can continue this offline.
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 10362555
Closed, no points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0
 

Expert Comment

by:Tinky_Lou
ID: 10734010
Do you mind posting the link to the spanish website, please?
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

695 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