how to show two tables in datagridview on clicking of one button

Posted by Aditya1234567 under C# on 3/18/2013 | Points: 10 | Views : 5602 | Status : [Member] | Replies : 2
how to show data of two tables in datagridview on a click of single button plz suggest me coding for that




Responses

Posted by: Jayakumars on: 3/18/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

use this 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();
}

Mark as Answer if its helpful to you

Aditya1234567, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 3/18/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
http://www.codeproject.com/Articles/304297/Data-from-Two-Tables-in-a-Single-DataGridView

If this post helps you mark it as answer
Thanks

Aditya1234567, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response