generate html file as output of database query using ASP.NET and C#


First get the assign all rquired database related objects and then follow up. The followiing demonstration is about with code skelton for generate html file as output of database query using ASP.NET and C#.

// DataBase Data Results

DataSet ds=new DataSet();

Query the database and load all the data in the DataSet then add using loop in the DataTable.
// DB Query Excution

int k=0;
int l=0;
SqlStr="select * from urDB..urTABLE";
if (ds !=null)

Build your Resulting dataing in the HTML format. using the below loop.
//Build the data in HTML Format
if (k != 0)

A string is used for building the data in HTMl format
// Build HTML Formatt


StrTable=StrTable + "<table cellpadding="\" cellspacing="\" border="\" height="\" width="\">";

StrTable=StrTable + "<tr><td width="\" nowrap="\"> Gem oF All </td>";

StrTable=StrTable+"<td>Total Block Time </td><td colspan="\" nowrap="\">Vivek </td>";

StrTable=StrTable + "</tr>";

// it is For New Row between Rows
StrTable=StrTable + "<tr><td colspan="\"> </td></tr>";


// Append With End Tags

StrTable=StrTable + "</table>";

If you want to save the result in the HTML file format follow the below steps.

// *** Write to file ***
// Specify file, instructions, and privelegdes
FileStream file = new FileStream("filename.html", FileMode.OpenOrCreate, FileAccess.Write);
// Create a new stream to write to the
fileStreamWriter sw = new StreamWriter(file);
// Write a string to the
// Close StreamWritersw.Close();
// Close filefile.Close();


Popular posts from this blog

ASP.NET website "Cannot read configuration file due to insufficient permissions" in IIS 7 and Windows Server 2008

Error occurred in deployment step 'Install app for SharePoint': The System Account cannot perform this action.

None of the selected features can be installed or upgraded. Setup cannot proceed since no