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
Solved

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

Posted on 2003-10-23
12
220 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

828 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