Solved

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

Posted on 2003-10-23
12
206 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powerN  challenge 3 57
noX challenge 17 92
Help to convert powershell script into a gui 9 140
egit plugin on eclipse 8 38
This is an explanation of a simple data model to help parse a JSON feed
This is about my first experience with programming Arduino.
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now