show data datagrid from two table

S

Selen

Hello,
My problem is that I want to show data in datagrid from two table.I have two
table tb_Eqp_Main and tb_Equipment they have a relationship with EqpNo...
I use da.Fill(dataset,Table name) but I dont know What must I write to
TableName...My code :

strConn="server=(local)\\sql2000;database=db_Kalite_Data;uid=sa;pwd=antalya"
;

SqlConnection conn=new SqlConnection (strConn);

conn.Open ();

string strCmd="select M.EqpNo,M.SerialNumber ,M.Description,Eqp.Tip" +

",Eqp.NextCalibration,Eqp.NextBakim,Eqp.NextSafety,M.Location,tip.TypeName "
+

" from tb_Eqp_Main as M ,tb_Equipment Eqp" +

", tb_Eqp_Type tip where tip.TypeId=Eqp.Description and M.EqpNo=M.EqpNo" ;


SqlCommand cmd=new SqlCommand (strCmd,conn);

SqlDataReader dr=cmd.ExecuteReader ();



SqlDataAdapter da=new SqlDataAdapter (strCmd,conn);

DataSet ds=new DataSet ();


da.Fill (ds,"???????");

dgEqp.DataSource =ds;

dgEqp.DataBind ();

Thanks....
 
G

Guest

You don't actually need a table name. In the dataset the tables are indexed so you can refer to them by their index value
Your query will only return one recordset

SqlDataReader dr=cmd.ExecuteReader ();
What's the use for this line?? If you are not using the datareader remove it

SqlDataAdapter da=new SqlDataAdapter (strCmd,conn);

The following would work

da.Fill(ds)
o
da.Fill(ds, "<any name you wish>"

dgEqp.DataSource = ds
o
dgEqp.DataSource = ds.Tables[0]
o
dgEqp.DataSource = ds.Tables["<the same name you gave in the fill method>"

dgEqp.DataBind ()

HTH
Suresh

----- Selen wrote: ----

Hello
My problem is that I want to show data in datagrid from two table.I have tw
table tb_Eqp_Main and tb_Equipment they have a relationship with EqpNo..
I use da.Fill(dataset,Table name) but I dont know What must I write t
TableName...My code

strConn="server=(local)\\sql2000;database=db_Kalite_Data;uid=sa;pwd=antalya


SqlConnection conn=new SqlConnection (strConn)

conn.Open ()

string strCmd="select M.EqpNo,M.SerialNumber ,M.Description,Eqp.Tip"

",Eqp.NextCalibration,Eqp.NextBakim,Eqp.NextSafety,M.Location,tip.TypeName


" from tb_Eqp_Main as M ,tb_Equipment Eqp"

", tb_Eqp_Type tip where tip.TypeId=Eqp.Description and M.EqpNo=M.EqpNo"


SqlCommand cmd=new SqlCommand (strCmd,conn)

SqlDataReader dr=cmd.ExecuteReader ()



SqlDataAdapter da=new SqlDataAdapter (strCmd,conn)

DataSet ds=new DataSet ()


da.Fill (ds,"???????")

dgEqp.DataSource =ds

dgEqp.DataBind ()

Thanks...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top