Solved

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

Posted on 2003-10-23
12
213 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to split this in C++ 4 102
move one pixel 4 67
iframe detection of parent window scale 20 72
VB.net and sql server 4 36
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
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…

772 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