Requirement - Excel sheet should be populated with data from the database
Issue - Excel sheet dialog box is opening with Open, save, Cancel.
But, there is again a dialog box which says that the file u are trying to open,'Rep.aspx' , is in a different format than specified by the file extension. verify that the file is not corruptedand is from a trusted source before opening the file. Do you want to open the file now?
When i say 'Yes', the data isnt populated but a blank excel sheet with column headers is seen.
Not able to spot where the problem is :(
public partial class Rep : System.Web.UI.P age
{
protected System.Web.UI.H tmlControls.Htm lTable tblExel;
SqlConnection conn = new SqlConnection(" ConnectionStrin g");
private void Page_Load(objec t sender, System.EventArg s e)
{
try
{
conn.Open();
Response.Clear( );
Response.Buffer = true;
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.Charse t = "";
SqlCommand cmd = new SqlCommand("Sel ect CubicleId,Emplo yeeNo,EmployeeN ame,Project,Ema ilId,Department ,DirectNo from PuneEmployee", conn);
SqlDataReader dr = cmd.ExecuteRead er();
while (dr.Read())
{
string CubicleId = dr.GetValue(0). ToString();
int EmployeeNo = Int32.Parse(dr. GetValue(1).ToS tring());
string EmployeeName = dr.GetValue(2). ToString();
string Project = dr.GetValue(3). ToString();
string EmailId = dr.GetValue(4). ToString();
string Department = dr.GetValue(5). ToString();
string DirectNo = dr.GetValue(6). ToString();
AddTableRow(Cub icleId, EmployeeNo, EmployeeName, Project, EmailId, Department, DirectNo);
}
dr.Close();
conn.Close();
}
catch (Exception ex)
{
Response.Write( ex);
}
}
private void AddTableRow(str ing CubicleId, int EmployeeNo, string EmployeeName, string Project, string EmailId, string Department, string DirectNo)
{
HtmlTableRow row1 = new HtmlTableRow();
row1.Height = "20";
HtmlTableCell cell1 = new HtmlTableCell() ;
HtmlTableCell cell2 = new HtmlTableCell() ;
HtmlTableCell cell3 = new HtmlTableCell() ;
HtmlTableCell cell4 = new HtmlTableCell() ;
HtmlTableCell cell5 = new HtmlTableCell() ;
HtmlTableCell cell6 = new HtmlTableCell() ;
HtmlTableCell cell7 = new HtmlTableCell() ;
cell1.Controls. Add(new LiteralControl( CubicleId));
cell2.Controls. Add(new LiteralControl( EmployeeNo.ToSt ring()));
cell3.Controls. Add(new LiteralControl( EmployeeName));
cell4.Controls. Add(new LiteralControl( Project));
cell5.Controls. Add(new LiteralControl( EmailId));
cell6.Controls. Add(new LiteralControl( Department));
cell7.Controls. Add(new LiteralControl( DirectNo));
row1.Cells.Add( cell1);
row1.Cells.Add( cell2);
row1.Cells.Add( cell3);
row1.Cells.Add( cell4);
row1.Cells.Add( cell5);
row1.Cells.Add( cell6);
row1.Cells.Add( cell7);
cell1.Width = "100";
cell2.Width = "250";
cell3.Width = "100";
cell4.Width = "100";
cell5.Width = "100";
cell6.Width = "100";
cell7.Width = "100";
tblExel.Rows.Ad d(row1);
}
0 923 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: sridevi |
last post by:
Hello
How to export data from ms-access database to excel worksheet using ASP.
mainly i need to export data to multiple worksheets. it is very urgent to
us.
i have a sample code which works only exporting to single worksheet. but i
need to export data to multiple worksheets.
it is very urgent to us. so please help me in code.
|
by: David Gartrell |
last post by:
Hi i'm trying to import an Excel Spreadsheet into Access2000 but the data
types for two of the fields in my imported table are being identified
incorrectly. Is there a way of using some VB code in Access to change the
data types for the fields from text to a number field or an Integer field.
I'd be grateful for any advice you could give
Many thanks
David
|
by: Liz |
last post by:
Hi! I have a .Net webpage that displays data in some datagrids populated
based on user search criteria. There is a button, that when clicked, the
data is exported to excel. For one user, I am seeing that it works
correctly the first time he tries the report, but if he reruns the
result set or even picks a different report, the web page itself is
exported to excel and not the data. He has the same Excel version as
others (Excel 2003) who...
|
by: Grey |
last post by:
I have created a asp.net form for user to input data. After input the data,
user need to click a button to export the input data to excel for data
analysis with excel pivot table function. is it possible to do that?? if so,
any sample for me as i am a new in designing pivot table with asp.net
million thanks
|
by: asad |
last post by:
hello, how ru all
pls tell me how can i create DAL and how can i use it in my ASP.NET pages
thanks
| |
by: 333sridhar333 |
last post by:
Hi,
I am having a problem in exporting a data from jsp to excel.
I am getting the values from a servlet and populating it to a JSP.
And form there i export them to Excel.
The functionality works fine. But the problem is with the exported data.
I am having values with leading zeros. for example:
Patron Code
|
by: 333sridhar333 |
last post by:
Hi,
I am having a problem in exporting a data from jsp to excel.
I am getting the values from a servlet and populating it to a JSP.
And form there i export them to Excel.
The functionality works fine. But the problem is with the exported data.
I am having values with leading zeros. for example:
Patron Code
|
by: cckelly |
last post by:
Hello, all!
I need help. There is a "view" in a SQL Server 7 database that contains all the data I need.
I want to create an Excel file (version Excel 2000). I want the file to open the view and refresh the data every time. (The view pulls records for the past 3 months.)
I've tried the Excel menu option "Data | Get External Data | New Database Query" to select the view from the list of database objects. A message appears and the Excel...
|
by: KeithChang |
last post by:
Hi, I'm building a web application in VB.NET 1.1 where users will upload Excel files at this webpage and the web application will transfer the data from the uploaded Excel file into MS SQL 2000. There are around 600-700 records and about 56 columns in the Excel file which is to be uploaded daily. There will be a few different files which I need to implement for as well.
I've sourced for and tried alot of methods. But either they can't satisfy...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |