Click here to Skip to main content
15,889,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using repeater in asp.net website, in this repeater i have labels in which i am showing data from database table.
eg:-
<asp:Label ID="lbl_state" runat="server" Text='<%#Eval("state") %>'>
here state data is state id which is numeric.

I have two tables in database 1.) register 2.) state
When i register product i save state id in register table for state.
and in state table i have state id and state name.

I am fetching data from register table so it is showing me state id.
But i want to bind state name instead of state id.
Posted

1 solution

Use a JOIN to fetch the data from both tables.

SQL
select r.*, s.StateName from Register r
INNER JOIN State s ON r.StateID = s.StateID


Now you can use the StateName.
 
Share this answer
 
Comments
Raj Negi 3-Apr-14 4:58am    
It works fine but I have one more question, if i have one more country table and similarly i want country name then how to integrate in this query.
Code Help 2014 3-Apr-14 6:02am    
Use a similar join with Country table. For example:

select r.*, s.StateName from Register r
INNER JOIN State s ON r.StateID = s.StateID
INNER JOIN Country c ON c.CountryID = s.CountryID
Raj Negi 4-Apr-14 3:34am    
okay good, One more last query, suppose if i fetch 0 and 1 in a label from database but i have no other table to join. I want, when i fetch 0 then it shows text "No" and when the value is 1 then it shows "Yes"...how to do this.
Code Help 2014 4-Apr-14 5:58am    
Suppose you have a table Student with column IsPass having value 0 and 1 then the query will be:
select CASE IsPass WHEN 1 THEN 'YES' ELSE 'NO' End as StdResult FROM Student

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