HOW TO DISPLAY 7 - Table data in gridview using asp c#
CREATE TABLE [dbo].[emp] (
[EMP_ID] NCHAR (6) NULL,
[PROJECT_ID] NVARCHAR (10) NULL,
[EMP_NAME] NVARCHAR (50) NULL,
[EMP_DSG] NVARCHAR (35) NULL,
[DEPT_ID] NVARCHAR (15) NULL,
[EMP_ADD] NVARCHAR (50) NULL,
[LOCATION_ID] NVARCHAR (50) NULL,
[EMP_DOB] NVARCHAR (15) NULL,
[DOJNTPC] NVARCHAR (50) NULL,
[PHONE_RESI] NVARCHAR (50) NULL,
[PHONE_OFF] NVARCHAR (50) NULL,
[VSAT_PHONE] NVARCHAR (50) NULL,
[EMAIL_ID] NCHAR (40) NULL,
[INTERCOM] NVARCHAR (50) NULL,
[S_GUID] UNIQUEIDENTIFIER NULL,
[PHONE_MOB] NCHAR (12) NULL,
[photo] IMAGE NULL,
[IsActive] BIT NULL,
[password] NVARCHAR (50) NULL
);
CREATE TABLE [dbo].[elec_comp_box_plant] (
[COMP_ID] INT IDENTITY (1, 1) NOT NULL,
[EMP_ID] NCHAR (10) NULL,
[COMP_MESSAGE] NVARCHAR (MAX) NULL,
[STATUS_ID] VARCHAR (255) DEFAULT ('Open') NULL,
[COMP_LODGE_DATE] DATETIME DEFAULT (getdate()) NOT NULL,
[CLOSING_DATE] DATETIME NULL,
[REMARKS] VARCHAR (255) NULL,
[S_GUID] UNIQUEIDENTIFIER NULL,
[remote_ip] NVARCHAR (50) NULL,
[who] NVARCHAR (50) NULL,
[user_feedback] NVARCHAR (255) NULL,
[type] NVARCHAR (255) NULL,
[ATTEND_DATE] DATETIME NULL,
[ATTEND_BY] VARCHAR (255) NULL,
[Image ] VARCHAR (50) NULL
);
CREATE TABLE [dbo].[elec_comp_box] (
[COMP_ID] INT IDENTITY (1, 1) NOT NULL,
[EMP_ID] NCHAR (10) NULL,
[COMP_MESSAGE] NVARCHAR (MAX) NULL,
[STATUS_ID] VARCHAR (255) DEFAULT ('Open') NULL,
[COMP_LODGE_DATE] DATETIME DEFAULT (getdate()) NOT NULL,
[CLOSING_DATE] DATETIME NULL,
[REMARKS] VARCHAR (255) NULL,
[S_GUID] UNIQUEIDENTIFIER NULL,
[remote_ip] NVARCHAR (50) NULL,
[who] NVARCHAR (50) NULL,
[user_feedback] NVARCHAR (255) NULL,
[type] NVARCHAR (255) NULL,
[ATTEND_DATE] DATETIME NULL,
[ATTEND_BY] VARCHAR (255) NULL,
[Image ] VARCHAR (255) NULL
);
CREATE TABLE [dbo].[comp_box] (
[COMP_ID] INT IDENTITY (1, 1) NOT NULL,
[EMP_ID] NVARCHAR (10) NULL,
[COMP_MESSAGE] NVARCHAR (MAX) NULL,
[STATUS_ID] NVARCHAR (10) DEFAULT ('Open') NOT NULL,
[COMP_LODGE_DATE] DATETIME DEFAULT (getdate()) NOT NULL,
[CLOSING_DATE] DATETIME NULL,
[REMARKS] VARCHAR (255) NULL,
[S_GUID] UNIQUEIDENTIFIER NULL,
[remote_ip] NVARCHAR (50) NULL,
[who] NVARCHAR (50) NULL,
[user_feedback] NVARCHAR (255) NULL,
[type] NVARCHAR (255) NULL,
[ATTEND_DATE] DATETIME NULL,
[ATTEND_BY] VARCHAR (255) NULL,
[Image ] VARCHAR (50) NULL
);
CREATE TABLE [dbo].[civil_comp_box_plnt] (
[COMP_ID] INT IDENTITY (1, 1) NOT NULL,
[EMP_ID] NCHAR (10) NULL,
[COMP_MESSAGE] NVARCHAR (MAX) NULL,
[STATUS_ID] VARCHAR (255) DEFAULT ('Open') NULL,
[COMP_LODGE_DATE] DATETIME DEFAULT (getdate()) NOT NULL,
[CLOSING_DATE] DATETIME NULL,
[REMARKS] VARCHAR (255) NULL,
[S_GUID] UNIQUEIDENTIFIER NULL,
[remote_ip] NVARCHAR (50) NULL,
[who] NVARCHAR (50) NULL,
[user_feedback] NVARCHAR (255) NULL,
[type] NVARCHAR (255) NULL,
[ATTEND_DATE] DATETIME NULL,
[ATTEND_BY] VARCHAR (255) NULL,
[Image ] VARCHAR (50) NULL
);
CREATE TABLE [dbo].[civil_comp_box] (
[COMP_ID] INT IDENTITY (1, 1) NOT NULL,
[EMP_ID] NCHAR (10) NULL,
[COMP_MESSAGE] NVARCHAR (MAX) NULL,
[STATUS_ID] VARCHAR (255) DEFAULT ('Open') NULL,
[COMP_LODGE_DATE] DATETIME DEFAULT (getdate()) NOT NULL,
[CLOSING_DATE] DATETIME NULL,
[REMARKS] VARCHAR (255) NULL,
[S_GUID] UNIQUEIDENTIFIER NULL,
[remote_ip] NVARCHAR (50) NULL,
[who] NVARCHAR (50) NULL,
[user_feedback] NVARCHAR (255) NULL,
[type] NVARCHAR (255) NULL,
[ATTEND_DATE] DATETIME NULL,
[ATTEND_BY] VARCHAR (255) NULL,
[Image ] VARCHAR (50) NULL
);
CREATE TABLE [dbo].[HR_comp_box] (
[COMP_ID] INT IDENTITY (1, 1) NOT NULL,
[EMP_ID] NCHAR (10) NULL,
[COMP_MESSAGE] NVARCHAR (MAX) NULL,
[STATUS_ID] VARCHAR (255) DEFAULT ('Open') NULL,
[COMP_LODGE_DATE] DATETIME DEFAULT (getdate()) NOT NULL,
[CLOSING_DATE] DATETIME NULL,
[REMARKS] VARCHAR (255) NULL,
[S_GUID] UNIQUEIDENTIFIER NULL,
[remote_ip] NVARCHAR (50) NULL,
[who] NVARCHAR (50) NULL,
[user_feedback] NVARCHAR (255) NULL,
[type] NVARCHAR (255) NULL,
[ATTEND_DATE] DATETIME NULL,
[ATTEND_BY] VARCHAR (255) NULL,
[Image ] VARCHAR (50) NULL
);
namespace OCMS
{
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["EmpId"]))
{
lblName.Text = Request.QueryString["EmpId"];
}
if (!this.IsPostBack)
{
string sql = "SELECT f.EMP_ID,f.EMP_NAME,a.COMP_ID,a.COMP_MESSAGE,b.STATUS_ID,c.COMP_LODGE_DATE,c.CLOSING_DATE,c.REMARKS FROM comp_box a INNER JOIN civil_comp_box b ON b.EMP_ID=a.EMP_ID INNER JOIN civil_comp_box_plnt c ON c.EMP_ID=a.EMP_ID INNER JOIN elec_comp_box d ON d.EMP_ID=a.EMP_ID INNER JOIN elec_comp_box_plant e ON e.EMP_ID=a.EMP_ID INNER JOIN emp f ON f.EMP_ID=a.EMP_ID where a.EMP_ID=" + lblName.Text + "";
//string sql = "SELECT f.EMP_ID,f.EMP_NAME,a.COMP_ID,a.COMP_MESSAGE,b.STATUS_ID,c.COMP_LODGE_DATE,c.CLOSING_DATE,c.REMARKS FROM comp_box a INNER JOIN civil_comp_box b ON b.EMP_ID=a.EMP_ID INNER JOIN civil_comp_box_plnt c ON c.EMP_ID=a.EMP_ID INNER JOIN elec_comp_box d ON d.EMP_ID=a.EMP_ID INNER JOIN elec_comp_box_plant e ON e.EMP_ID=a.EMP_ID INNER JOIN emp f ON f.EMP_ID=a.EMP_ID where a.EMP_ID=" + 007221 + "";
GridView1.DataSource = this.GetData(sql);
GridView1.DataBind();
}
}
private DataTable GetData(string sql)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sql))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
cmd.Connection = con;
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}
}
}