Solved

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

Posted on 2003-10-23
12
228 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Selenium and Interactive Data Language 3 76
SQL Insert parts by customer 12 61
$_GET call between URL 3 67
Eclipse neon2 "Java build path" correctness 7 43
This article will show, step by step, how to integrate R code into a R Sweave document
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

734 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