Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    2
    ReputationRep:
    Hi there, I have the following SQL query

    "SELECT TOP '" + q + "' questionID FROM Question WHERE courseID = '" + c + "' ORDER BY Rnd(questionID)"

    where q and c are variables passed into the method containing this query as arguments

    this is returning null, when I know that q and c definately have appropiaote values in them, why is this??

    Any help somebody can give me would be great, many thanks.
    Offline

    0
    ReputationRep:
    This query will return some tuple if q > 0 and c is a existing courseID.
    The "order by" doesn't influence
    Your Question table is big? You can show it?
    Post the table and parameters q and c that you tested and returned null.
    • Thread Starter
    Offline

    2
    ReputationRep:
    (Original post by felipe87)
    This query will return some tuple if q > 0 and c is a existing courseID.
    The "order by" doesn't influence
    Your Question table is big? You can show it?
    Post the table and parameters q and c that you tested and returned null.
    Thank you for your reply.

    Yes, I have prepared for it to return more than one row, yes c is an exisitng courseID.
    ok.
    No there aren't many questions there at the moment, but it will have.
    Name:  QuestionTable.png
Views: 113
Size:  21.1 KB

    I get a nullReference in my c# code from the List<int> that the method containing the query returns to
    Offline

    0
    ReputationRep:
    I created a table like you in MS Access and following SQL:
    Code:
    SELECT top 1 Question.[questionID]
    FROM Question
    where Question.[courseID] = 'AWD01'
    order by Rnd(Question.[questionID]);
    And works!
    You are using quote to courseID column?
 
 
 
Poll
Do you agree with the PM's proposal to cut tuition fees for some courses?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.