In SQL Server, first we create one table, tbl_EmpDetails.
- CREATE TABLE [dbo].[tbl_EmpDetails](
- [EmpID] [int] IDENTITY(1,1) NOT NULL,
- [EmpName] [varchar](100) NOT NULL,
- [EmpAddress] [nvarchar](100) NOT NULL,
- [Mobile] [varchar](20) NOT NULL,
- [EmailID] [nvarchar](50) NOT NULL,
- [DOB] [varchar](50) NOT NULL,
- CONSTRAINT [PK_tbl_EmpDetails] PRIMARY KEY CLUSTERED
- (
- [EmpID] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
- ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- GO
- INSERT INTO tbl_EmpDetails Values('Anil','Mumbai',1233456789,'[email protected]','1989-10-10')
- INSERT INTO tbl_EmpDetails Values('Suresh','Mumbai',1233456789,'[email protected]','1989-10-10')
- INSERT INTO tbl_EmpDetails Values('Ramesh','Mumbai',1233456789,'[email protected]','1989-10-10')
Now, we create ASP.Net Web Application.

Add below namespace,
- using System.Text;
- using System.Data.SqlClient;
- using iTextSharp.text;
- using iTextSharp.text.pdf;
- using iTextSharp.text.html.simpleparser;
- using System.Data;
- using System.Configuration;
- using System.IO;
On page load we bind grid as below code .
- public partial class EmployeeList : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- BindGrid();
- }
- }
In BindGrid function we get data from database and store value in session.
- protected void BindGrid() {
- DataTable dt = new DataTable();
- string queryString = "select * from tbl_EmpDetails";
- string conn = ConfigurationManager.ConnectionStrings["TestConnectionString"].ToString();
- var table = new DataTable();
- using(SqlConnection sql = new SqlConnection(conn)) {
- SqlCommand command = new SqlCommand(queryString, sql);
- sql.Open();
- SqlDataAdapter da = new SqlDataAdapter(command);
- da.Fill(table);
- sql.Close();
- da.Dispose();
- }
- dt = table;
- GridView1.DataSource = dt;
- GridView1.DataBind();
- Session["Data"] = dt;
- }




Ram AkAPosted Dec 25, 2020, 12:06 PM
It is very useful to thank u so much bro