473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Data not getting populated in excel - See code below

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.Page
{
protected System.Web.UI.HtmlControls.HtmlTable tblExel;

SqlConnection conn = new SqlConnection("ConnectionString");

private void Page_Load(object sender, System.EventArgs e)
{
try
{
conn.Open();
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";


Response.Charset = "";

SqlCommand cmd = new SqlCommand("Select CubicleId,EmployeeNo,EmployeeName,Project,EmailId, Department,DirectNo from PuneEmployee", conn);
SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
string CubicleId = dr.GetValue(0).ToString();
int EmployeeNo = Int32.Parse(dr.GetValue(1).ToString());
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(CubicleId, EmployeeNo, EmployeeName, Project, EmailId, Department, DirectNo);


}
dr.Close();
conn.Close();
}
catch (Exception ex)
{
Response.Write(ex);
}



}

private void AddTableRow(string 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.ToString()));

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.Add(row1);

}
Apr 9 '08 #1
0 908

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
6
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...
0
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...
1
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...
2
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
1
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...
2
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...
2
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...
8
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....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.