0

Hi everyone,

I am trying to populate a gridview.

this is my table structure:
Modules - M_ID, M_title (this is where the module info is stored)
Module_course_link - MC_ID, M_ID, C_ID (this table links the Modules and Courses table)
Courses - C_ID, C_title (this is where the course info is stored)

this is where I get the C_ID
<code>string C_ID = Request.QueryString["C_ID"]; (this works)</code>

what I need help with is, to populate the gridview, at the moment I'm using this syntax,
I want the MC_ID to be the DataKeyName of the gridview, at the moment only M_title AS Modules are displayed.

How can I change the select query to do this and not return the error:
At most one record can be returned by this subquery.

AccessDataSource1.SelectCommand =
        "SELECT M_title AS Modules FROM Modules WHERE M_ID IN (Select MC_ID From Module_course_link Where C_ID= " + C_ID + ")";
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by rohand
0

Try to execute below modified query :

string C_ID = Request.QueryString["C_ID"]; (this works)

SELECT mcl.MC_ID as MC_ID, m.M_title as Modules 
From Modules m
Join Module_course_link mcl on mcl.M_ID = m.M_ID
Where
mcl.C_ID = C_ID

Now you can set MC_ID as DataKeyNames of your GridView..

Try by this and let us know..

Hi everyone,

I am trying to populate a gridview.

this is my table structure:
Modules - M_ID, M_title (this is where the module info is stored)
Module_course_link - MC_ID, M_ID, C_ID (this table links the Modules and Courses table)
Courses - C_ID, C_title (this is where the course info is stored)

this is where I get the C_ID
<code>string C_ID = Request.QueryString["C_ID"]; (this works)</code>

what I need help with is, to populate the gridview, at the moment I'm using this syntax,
I want the MC_ID to be the DataKeyName of the gridview, at the moment only M_title AS Modules are displayed.

How can I change the select query to do this and not return the error:
At most one record can be returned by this subquery.

AccessDataSource1.SelectCommand =
        "SELECT M_title AS Modules FROM Modules WHERE M_ID IN (Select MC_ID From Module_course_link Where C_ID= " + C_ID + ")";
0

Try to execute below modified query :

string C_ID = Request.QueryString["C_ID"]; (this works)

SELECT mcl.MC_ID as MC_ID, m.M_title as Modules 
From Modules m
Join Module_course_link mcl on mcl.M_ID = m.M_ID
Where
mcl.C_ID = C_ID

Thank you, but I received an error:
Syntax error in FROM clause.

0
AccessDataSource1.SelectCommand = "SELECT mcl.MC_ID as MC_ID, m.M_title as Modules From Modules m Join Module_course_link mcl on mcl.M_ID = m.M_ID Where mcl.C_ID = C_ID "

that's all...

Try to execute below modified query :

string C_ID = Request.QueryString["C_ID"]; (this works)

SELECT mcl.MC_ID as MC_ID, m.M_title as Modules 
From Modules m
Join Module_course_link mcl on mcl.M_ID = m.M_ID
Where
mcl.C_ID = C_ID

Thank you, but I received an error:
Syntax error in FROM clause.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.