Introduction
In this article, you will learn how to create an HTML report using inline code in ASP.NET.
In one of my previous articles, I explained the Difference between Inline Code and Code Behind, in this article, we will use inline code to create an HTML report.
Step 1. First of all, create a new empty website in your Visual Studio.

Now right-click on your website name and then add a new Web Page but while adding this new page ensure that you uncheck the "Place Code in Separate File", otherwise it will not be inline code.

Step 2. Now create a database of any name and add one table to it. Make some entries in this new table and save it. For here I created a database named "Test" and a table added to it named "Employee".

Now in Visual Studio add this database by adding it through Server Explorer. Provide all the necessary details for the connection and connect to it.

Step 3. Now you need to add a class through which a connection to this database will be declared, for again right-click on your website click on "Add New Item" and then add the class.
In this class, a connection will be created that will help us to fetch the data from the database. Here the connectme function is used to make the connection with the database and the getvalue function is used to read the data from the database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
public class callme
{
public SqlConnection x = new SqlConnection();
public SqlCommand y = new SqlCommand();
public SqlDataReader z;
public void connectme()
{
x.Close();
x = new SqlConnection(@"Data Source=MCNDESKTOP20;Initial Catalog=test;User ID=sa;Password=**********");
x.Open();
}
public void getvalue(string task)
{
connectme();
y = new SqlCommand(task, x);
z = y.ExecuteReader();
}
}



Comments
Join the conversation! Your thoughts help the community grow.