show two tables in datagridview on clicking of one button

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 938
hi
I have post the Code

show two tables in datagridview on clicking of one button following Code.



CREATE TABLE [dbo].[Tbl_Emp](
[EmpId] [int] IDENTITY(1,1) NOT NULL,
[Empname] [varchar](50) NULL,
[DeptId] [int] NULL,
CONSTRAINT [PK_Tbl_Emp] 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]





CREATE TABLE [dbo].[Tbl_Dept](
[DeptId] [int] IDENTITY(1,1) NOT NULL,
[Dept] [varchar](50) NULL,
CONSTRAINT [PK_Tbl_Dept] PRIMARY KEY CLUSTERED
(
[DeptId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


string strConnString = ConfigurationManager.ConnectionStrings["CntString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{

}
void bindgrid()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "SELECT Empid,Empname,Dept from Tbl_Emp T1,Tbl_Dept T2 where T1.DeptId=T2.DeptId";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "student");
Grd1.DataSource = ds;
Grd1.DataBind();
con.Close();

}
protected void Bt_Submit_Click(object sender, EventArgs e)
{
bindgrid();
}

Comments or Responses

Login to post response