Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have table for topics which contains topicTitle, periodId but i want to use period name from other table instead of periodId and i want to add url to topic title in the gridview, how can i do that ? i am using asp.net c#
thanks
Posted
Comments
KM Perumal 2-May-13 9:09am    
post ur code
Salah Abualrob 2-May-13 9:14am    
i have to get each periodId from gridview and then retrieve period for each one of then
this code for the first table, but i dont know what to do now!
if (Session["MenuItem"] != null)
{
string s = Session["MenuItem"].ToString();
int TypeId = getTypeId(Session["MenuItem"].ToString());
Adapter = new SqlDataAdapter("SELECT Title,AgeId FROM Subjects WHERE CId = '" + TypeId + "'", con);
Adapter.Fill(ds, "Subjects");
Adapter.Dispose();
GridView1.DataSource = ds.Tables["Subjects"];
GridView1.DataBind();
}
Member 9581488 2-May-13 9:17am    
if you have two tables then you should use join!
http://www.w3schools.com/sql/sql_join.asp
the above url might help you!

Use Inner Join
Inner join Examable[^]
 
Share this answer
 
example from what KM Perumal suggested:
SQL
SELECT a.topicid, a.periodid, b.topicTitle, c.periodName FROM myTable a
INNER JOIN topic b ON a.topicid = b.topicid
INNER JOIN period c ON a.periodid = c.periodid;
 
Share this answer
 
v2
Comments
Salah Abualrob 2-May-13 9:58am    
Subjects table:
SubjectId,Title,Content,UserId,AgeId,ClassificationId

AgePeriods table:
AgePeriodId,Period

and this select statment which i wrote:
"SELECT Subjects.SubjectId,Subjects.UserId,AgePeriods.Period From Subjects WHERE CId = '" + TypeId + "' INNER JOIN AgePeriods ON Subjects.CID = AgePeriods.AgePeriodId ORDER BY Subjects.SubjectId"

but it says "System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'INNER'.", what's wrong ?!
Member 9581488 2-May-13 11:15am    
SELECT Subjects.SubjectId,Subjects.UserId,AgePeriods.Period From Subjects
INNER JOIN AgePeriods ON Subjects.CID = AgePeriods.AgePeriodId
WHERE CId = '" + TypeId + "'
ORDER BY Subjects.SubjectId

Use above query
Salah Abualrob 2-May-13 18:15pm    
Thanks all, solved :)

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