CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.web_forms Tags:
Item Type: NewsGroup Date Entered: 11/14/2003 6:13:05 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 9 Views: 3 Favorited: 0 Favorite
10 Items, 1 Pages 1 |< << Go >> >|
pietaster
Asp.Net User
I need to download data to excel11/14/2003 6:13:05 PM

0

This is what I am doing:


DataSet ds = SqlHelper.ExecuteDataset(SPString, CommandType.StoredProcedure, "sp_name", parameters);
dgdownload.DataSource = ds.Tables[0];
dgdownload.DataBind();

// Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel";

// Remove the charset from the Content-Type header.
Response.Charset = "";

// Turn off the view state.
Page.EnableViewState = false;

// Get the HTML for the control.
dgdownload.RenderControl(new HtmlTextWriter(tw));
tw.Flush();
tw.Close();


I got this code from many threads from this forum but I am having a problem.

The file downloads fine but at the end of file I get this error


The Following Exception occured. Exception : System.NullReferenceException: Object
reference not set to an instance of an object. at
System.Web.UI.HtmlTextWriter.RenderBeginTag(HtmlTextWriterTag tagKey) at
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) at
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at
System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) at
System.Web.UI.WebControls.BaseDataList.Render(HtmlTextWriter writer) at
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at
Speedpay.download.Page_Load(Object sender, EventArgs e) in
c:\appsdev\speedpayrpt\speedpay\download.aspx.cs:line 91 Source : System.Web


How do I get rid of this error?

thanks,
pietaster,

A jury consists of twelve persons chosen to decide who has the better lawyer.
- Robert Frost (1874 - 1963)
mikepope
Asp.Net User
Re: I need to download data to excel11/15/2003 4:34:26 AM

0

I have this, courtesy of Colt Kwong, that seems to work. (It's in VB, but hopefully that won't be a problem.) It assumes that you've got a DataGrid1 control that is configured to be data-bound, etc.
Sub Page_Load()

DataGrid1.DataBind()
Response.ContentType = "application/vnd.ms-excel"
Dim tw As New System.IO.StringWriter()
Dim hw As new System.IO.HtmlTextWriter(tw)
DataGrid1.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
End Sub

-- Mike Pope

ASP.NET User Education

This posting is provided "AS IS" with no warranties, and confers no rights.

pietaster
Asp.Net User
Re: I need to download data to excel11/17/2003 2:30:36 PM

0

I am using the above and I still get the error.
pietaster,

A jury consists of twelve persons chosen to decide who has the better lawyer.
- Robert Frost (1874 - 1963)
mikepope
Asp.Net User
Re: I need to download data to excel11/17/2003 3:11:32 PM

0

The following example works for me (you'll need to substitute a connection string). Is there a possibility that you are not getting back from your data access class the information you think you are?
<%@ Page Language="C#" %>

<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.IO" %>
<script runat="server">

void Button1_Click(object sender, EventArgs e) {
//DataSet ds = SqlHelper.ExecuteDataset(SPString, CommandType.StoredProcedure, "sp_name", parameters);
DataSet ds = GetData();
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
dgdownload.DataSource = ds.Tables[0];
dgdownload.DataBind();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Page.EnableViewState = false;
dgdownload.RenderControl(new HtmlTextWriter(tw));
tw.Flush();
tw.Close();
}

DataSet GetData() {
// Substitute a connection string
string connectionString = "server=MYSERVER; trusted_connection=true; database=DATABASE";
SqlConnection dbConnection = new SqlConnection(connectionString);

// Substitute a query
string queryString = "SELECT GuestName, EntryDate, Comment FROM Guestbook";
SqlCommand dbCommand = new SqlCommand(queryString, dbConnection);

SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = dbCommand;
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
return dataSet;
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
</p>
<p>
<asp:DataGrid id="dgdownload" runat="server"></asp:DataGrid>
</p>
</form>
</body>
</html>

-- Mike Pope

ASP.NET User Education

This posting is provided "AS IS" with no warranties, and confers no rights.

pietaster
Asp.Net User
Re: I need to download data to excel11/17/2003 4:08:17 PM

0

I run the query and I get x number of records. When I do the web page I get the same number of records and error comes at the end.
pietaster,

A jury consists of twelve persons chosen to decide who has the better lawyer.
- Robert Frost (1874 - 1963)
pietaster
Asp.Net User
Re: I need to download data to excel11/17/2003 6:00:43 PM

0

It must have had to do with the placement of


StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);


before the datasource

pietaster,

A jury consists of twelve persons chosen to decide who has the better lawyer.
- Robert Frost (1874 - 1963)
pietaster
Asp.Net User
Re: I need to download data to excel11/17/2003 8:34:37 PM

0

I ran into another problem. The data I am downloading includes an account number, this number can contain up to 15 characters. When excel opens the accountnumnber file is not interpret right. I need it to display as text not a number.

How can I do this?

pietaster,

A jury consists of twelve persons chosen to decide who has the better lawyer.
- Robert Frost (1874 - 1963)
mikepope
Asp.Net User
Re: I need to download data to excel11/18/2003 7:37:36 AM

0

No, not sure what to do about that. It looks like it might (?) be an Excel thing. I experimented by converting numeric data in a particular column to a string before it's displayed in the DataGrid control, but Excel doesn't care. Makes sense, since the data really is a string in the resulting output, so Excel is apparently inferring the data type of the information in a given column from the contents in it. You might have some luck (?) in searching to find out if anyone knows how Excel treats HTML tables, which is basically what's going on here. Perhaps the Excel documentation itself addresses the issue of importing text.
-- Mike Pope

ASP.NET User Education

This posting is provided "AS IS" with no warranties, and confers no rights.

pietaster
Asp.Net User
Re: I need to download data to excel11/18/2003 12:59:57 PM

0

thanks for all your help.
pietaster,

A jury consists of twelve persons chosen to decide who has the better lawyer.
- Robert Frost (1874 - 1963)
staplefordbill
Asp.Net User
Re: I need to download data to excel12/1/2003 11:00:30 AM

0

I had a similar problem. Customer codes with a leading zero - e.g. 0123 - were displayed as 123 in Excel. The only solution I found was to put a non-breaking space on the end of the value to ensure Excel interprets it as a string. E.g.:


<table>
<tr>
<td>0123&nbsp;</td>
</tr>
</table>


An ordinary space doesn't work as Excel strips them out.
Bill.
10 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Microsoft Office Specialist Excel 2003: Study Guide Authors: Linda F. Johnson, Pages: 474, Published: 2006
Beginning Excel Services Authors: Liviu Asnash, Eran Megiddo, Craig Thomas, Pages: 404, Published: 2007
Online Investing Hacks: 100 Industrial-Strength Tips & Tools Authors: Bonnie Biafore, Pages: 483, Published: 2004
EBay Powerseller Secrets: Insider Tips from EBay's Most Successful Sellers Authors: Brad Schepp, Pages: 408, Published: 2004
How to Do Everything with Web 2.0 Mashups Authors: Jesse Feiler, Pages: 303, Published: 2007
Macromedia Studio MX 2004 All-in-one Desk Reference for Dummies: All-in-one Desk Reference for Dummies Authors: Damon Dean, Andy Cowitt, Ellen Finkelstein, Doug Sahlin, Camille McCue, Pages: 888, Published: 2003
Lean Six Sigma for Supply Chain Management: The 10-step Solution Process Authors: James William Martin, Pages: 411, Published: 2006
Yahoo! Hacks: Tips & Tools for Living on the Web Frontier Authors: Paul Bausch, Pages: 464, Published: 2005
Professional Visual Studio 2005 Team System Authors: Jean-Luc David, Tony Loton, Erik Gunvaldson, Noah Coad, Christopher Bowen, Darren Jefford, Pages: 700, Published: 2006
How to Do Everything with Microsoft Office Excel 2007 Authors: Guy Hart-Davis, Pages: 488, Published: 2006

Web:
Free Microsoft Excel add-in download - Excel spreadsheet free ... If you use MS Excel, you'll need to download and install Extools add-in. Perform complicated spreadsheet tasks easily even if you've never had Microsoft ...
Excel 2007 | Free Download Excel 2007 | Try Microsoft Office 2007 Excel 2007. Download Excel 2007 and manage information more effectively. ... Download a free trial-version of Microsoft Excel 2007 now, and start tracking data, ... you need by taking advantage this free trial of Microsoft Excel 2007. ...
how to download stock data into excel & acces http://www.gummy-stuff.org/Excel-Download-Webpage.htm ... I want to see the daily data and marvel at it, but I don't need to retain it. ...
Macro help - search for text in Excel Now it's time to get rid of the data you don't care about. ... We need to download them one by one for further processing. ...
OTN Discussion Forums : Download CLOB data to Excel ... Download CLOB data to Excel Posted: Jan 22, 2009 5:23 AM ... I need to download it to a Excel again. I have done the required functionality. ...
Import the data from web pages and Gedcom files directly into Excel Instead, retrieve the data in Excel, sort and manipulate the data any way that you ... and Web-to-ExcelR. I just need to download the most recent update. ...
Download these macros to help your users easily reformat Excel data Apr 27, 2008 ... Find out how our Excel data formatting macros download can help your ... This download contains all the components you need to provide a ...
Download Data Cell Excel .Net Free Trial - XLS to HTML conversion ... Nov 21, 2008 ... With the help of Data Cell Excel .Net component it's easily to export ... You need just 3 lines source code for successful conversion. ...
Excel Help for Automating a web query login to download data Excel Help for Automating a web query login to download data in ... Unfortunately I don't really understand which parameters I need to stick ...
VUMC Post Office Station 17 - Download Data Page This is what you need to select in the Excel text wizard's second screen. ... Select the data list(s) you wish to download. Lists are generated from the ...

Videos:
Daxian X999 Review Part 1 A Special Review of the Daxian X999. Part 2: http://youtube.com/watch?v=3mUE94MYTeE Correction: The Daxian X999 will not have upgrades like GPS ...
Learn Excel from Mr Excel - Episode 124 Export Excel Data for Other Applications - Do you need to transfer your budget figures from Excel back to your company's accounting records ...
Daxian X999 Review Part 2 A Special Review of the Daxian X999. Find it at: http://www.tronicvasion.com/category/363941 http://www.gadgetgodfather.com/ (Requires VIP ...
Learn Excel Episode 516 - Event Handlers In honor of Memorial Day in the United States, a question sent in from a naval aviator who has to enter a series of time values. Using a tiny bit ...
[Tutorial] iphpPod- Download and view movies- NO COMPUTER! phpPod is available through Installer.app Additional packages to install ffmpeg, and to install correct configuration files for Apache/PHP are ...
Learn Excel Episode 159 - Get characters up to the Dash The Left, Mid, Right functions are great, but what if you need to grab a variable number of characters from the left portion of the cell? For ...
How To Download Microsoft Office 2003 For Free! - No Serial ... Ok these are the links you will need. WINRAR: http://www.rarlab.com/rar/wrar380.exe BitTorent: http://www.oldapps.com/bittorrent.php ...
Learn Excel from MrExcel Episode 711 - Show Pages Do you ever need to produce a report for every customer? This is a snap with pivot tables in Excel 2007. In Episode 711, we take a look at how to ...
MrExcel's Learn Excel #944 - Excel to Word In Episode 943, I took data from Word and pasted to Excel for sorting. Now, I need to "type" that data back into Word, using the proper Style for ...
Learn Excel from MrExcel Episode 890 - Offset as TableArray An alternative to Episode 889...If you need to match two sorted columns with a VLOOKUP, you can make the table array be dynamically calculated ...






bc30311: value of type 'string' cannot be converted to 'system.web.ui.webcontrols.textbox'.

trasnfer text from one web form to another in c#

datagrid link

is there a smart usage of menu component with xml datasource?

variable memory size

filestream question

taking print out?

multivew and validators

html attachment

use the value of a string as the name for a pre-existing control

nested repeater controls

need new treeview control

tracking current user details

how to stop page redirect when "enter" pressed

handle keypress event on a webform?

is it possible to handle event of web control at client side??

debugging a custom .dll

2 submit forms in one aspx page

coded sms gateway

page unload

mail receiving in spam box

how to make tomorrow and yesterday date

insert and retrive a word doc

trouble with a webb poll.

100000000000 to 100,000,000,000 ?

non-invocable member: context.items()

print many pages on automatic

ultragrid control - is there any set focus property?????????

how do i put the listbox data into the sqldatabase?

issue with adding "click" event dynamically to imagebutton

   
  Privacy | Contact Us
All Times Are GMT