C# .NET - html for Dbase - Asked By mohamed on 15-Nov-11 06:17 AM

how i can make a html page and take a code from database
Suchit shah replied to mohamed on 15-Nov-11 06:33 AM

The process you follow would be pretty much dependent on the business logic.

For example, if you have all the data in a database, most likely a SQL Server and currently all the aspx pages are retreiving data from the database and displaying it then you can try the following steps.
You can write scripts in C# or other language,

  • Connect to the database and retrieve the necessary data and stored them in variables.
  • Create a file using the script and start writing to it.
  • Start writing html code to the file (for example, response.write(@"<html><head>");).
  • Write the value of the variables to the file.
  • Then save the file to a location in the web server.
  • You can run the scripts using schedules task or by writing listeners.

This way you can create html files and save them to the server.

You will need to make decision as to how often you run the scripts to generate the html files. You will also need to understand that the data in the pages will be as current as you run the scripts.

How to implement an ajax incremental page loading pattern. http://www.asp.net/learn/ajax-videos/video-118.aspx

There is a very useful utility at http://www.codeplex.com/HtmlTextWriterUtil for converting html to C# code to generate it.



Kirtan Patel replied to mohamed on 15-Nov-11 12:48 PM
you can do it like below code 

protected void Button1_Click(object sender, EventArgs e)
{
  SqlConnection con = new SqlConnection("Connection String");
  con.Open();
  SqlCommand comm = new SqlCommand("SELECT HTmlCode FROM table WHERE id=@id", con);
  comm.Parameters.Add("@id", TextBox1.Text);
  string code  = comm.ExecuteScalar().ToString();
 
  /* Close the Connection*/
  con.Close();
  Response.Write(code);
}