Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i have a problem.. i don't know how to bind data that has its own ID from same table into a gridview.
C#
SqlDataAdapter sqlcom0 = new SqlDataAdapter("select no_of_train from transshipment where id_transshipment =1", myConnection);

DataSet ds0 = new DataSet();
sqlcom0.Fill(ds0, "transshipment");
gd_transshipment.DataSource = ds0.Tables["transshipment"].DefaultView;
gd_transshipment.DataBind();

SqlDataAdapter sqlcom10 = new SqlDataAdapter("select no_of_train from transshipment where id_transshipment =2", myConnection);

DataSet ds10 = new DataSet();
sqlcom10.Fill(ds10, "transshipment");
gd_transshipment.DataSource = ds10.Tables["transshipment"].DefaultView;
gd_transshipment.DataBind();

when i run the website, the result display the both columns of gridview with the data id_transshipment=2.
i want it to be column1 = data that has id_transshipment=1 then column2 = data that has id_transshipment=2

i really hope someone can help me to figure it out.

thanks in advance.
Posted
Updated 5-Jan-12 23:37pm
v2

1 solution

Try this ,

C#
SqlDataAdapter sqlcom0 = new SqlDataAdapter("select no_of_train from transshipment where id_transshipment  in (1,2)", myConnection);

       DataSet ds0 = new DataSet();
       sqlcom0.Fill(ds0, "transshipment");
       gd_transshipment.DataSource = ds0.Tables["transshipment"].DefaultView;
       gd_transshipment.DataBind();
 
Share this answer
 
Comments
musiw 12-Jan-12 3:24am    
hi rahul,

sorry for the late reply..i just try your code.TQ.something better than me..hehe..but it still dont display exactly i want.

Transshipment

EMU | Intercity
No.of trains 1 1
No.of trains - -

my code display like this:


Transshipment

EMU | Intercity
No.of trains - -

and it should be like this:


Transshipment

EMU | Intercity
No.of trains 1 -

can help me on this?

thanks in advance
RDBurmon 12-Jan-12 3:29am    
Ok , Could you please post here the data in transshipment ?
musiw 12-Jan-12 4:05am    
table - transshhipment

id | id_transshipment | no_of_train | date
1 1 1 2/1/2012
2 2 - 2/1/2012

table class_transshipment

id_transshipment | desc_
1 EMU
2 Intercity

i want to display the transshipment data into gridview according by date.when user enter 2/1/2012 then the data will display.

i hope this will make you understand.
RDBurmon 12-Jan-12 4:58am    
But the sql "select no_of_train from transshhipment where id_transshipment in (1,2)" which you are using in your code it will return
no_train
1
0

and which is correct as per your requirement.

Ok , Could you please post your latest C# code ?
musiw 12-Jan-12 7:46am    
EMU | Intercity
No.of trains 1 -

this is actually what i want.only appear 1 row for the data according to date 2/1/2012. EMU/Intercity is a class of train.no of train is actually available train for that day (2/1/2012)

my code is from you. i just copy directly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900