0

How can I retrive random random ItemIDs from the list of existing ItemIDs in ItemID column intge db, given below is the sqlcommand I've used.

(SqlCommand RetrieveComm =new SqlCommand("SELECT * FROM item_k WHERE ItemID='" +intGetRequest+ "'", searchCon))

thanks,

0

2 Answers 2

2

Is the itemID column in the database, a contiguous list of numbers ?

If so, you can just do...

Random r = new Random();
int x = r.Next(1, MAX_ID_FROM_DB);
Sign up to request clarification or add additional context in comments.

Comments

1

You have not specified which RDBMS you are using.

If you are using SQL Server, this will return N random rows:

SELECT TOP N    
    SomeColumn 
FROM     
    SomeTable
ORDER BY     
    CHECKSUM(NEWID())

2 Comments

I didnt get your code! I need to get the itemIDs as well as other values.
So SELECT TOP N * FROM item_k ORDER BY CHECKSUM(NEWID()), no?!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.