473,471 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with a SQL Statement

The SQL I am using is supposed to grab only 6 titles from the database
and randomly display them on the default page. When I add more titles
to the database the initial 6 turns into 7,8,9 - 14 titles. Any
pointers. The SQL I am using is below:

Dim strSQL as string = "SELECT TOP 6 ASIN, strTitle, strArtist,
strReview, strImageDir " & _
"FROM tblDescription " & _
"ORDER BY SIN(tblDescription.decPrice * " &
rnd() & ");"

Dim objDataReader as OLEDBDataReader
objConn.Open()

Dim objCommand as new OLEDBCommand(strSQL,objConn)
dlMusic.DataSource =
objCommand.ExecuteReader(CommandBehavior.CloseConn ection)
dlMusic.DataBind()
dlMusic.RepeatColumns = 2

Nov 19 '05 #1
2 1019
Hi, Sparky,

Maybe these articles are kind of help:
http://www.sqlteam.com/item.asp?ItemID=896
http://dotnetjunkies.com/WebLog/mame.../11/13334.aspx

Gaidar

"Sparky Arbuckle" <tw*@secureroot.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
The SQL I am using is supposed to grab only 6 titles from the database
and randomly display them on the default page. When I add more titles
to the database the initial 6 turns into 7,8,9 - 14 titles. Any
pointers. The SQL I am using is below:

Dim strSQL as string = "SELECT TOP 6 ASIN, strTitle, strArtist,
strReview, strImageDir " & _
"FROM tblDescription " & _
"ORDER BY SIN(tblDescription.decPrice * " &
rnd() & ");"

Dim objDataReader as OLEDBDataReader
objConn.Open()

Dim objCommand as new OLEDBCommand(strSQL,objConn)
dlMusic.DataSource =
objCommand.ExecuteReader(CommandBehavior.CloseConn ection)
dlMusic.DataBind()
dlMusic.RepeatColumns = 2

Nov 19 '05 #2
The SQL TOP keyword instructs the db engine to bring the top n records from
the table or result set but SQL doesn't know how to distinguish between
records with equal position in the sort order.

If your data is such that there are more than 1 records in position 6 in the
ordering it will fetch them all.

if your results are
a
b
c
d
e
f
g
h

then SELECT TOP 6 will bring back a, b, c, d, e, f

but if your result set is
a
b
c
d
e
f
f
f
f
g

then SELECT TOP 6 will bring back a, b, c, d, e, f, f, f, f

You can usually get round this by including a unique column in your sort
clause.

Brian
----@

then
"Sparky Arbuckle" <tw*@secureroot.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
The SQL I am using is supposed to grab only 6 titles from the database
and randomly display them on the default page. When I add more titles
to the database the initial 6 turns into 7,8,9 - 14 titles. Any
pointers. The SQL I am using is below:

Dim strSQL as string = "SELECT TOP 6 ASIN, strTitle, strArtist,
strReview, strImageDir " & _
"FROM tblDescription " & _
"ORDER BY SIN(tblDescription.decPrice * " &
rnd() & ");"

Dim objDataReader as OLEDBDataReader
objConn.Open()

Dim objCommand as new OLEDBCommand(strSQL,objConn)
dlMusic.DataSource =
objCommand.ExecuteReader(CommandBehavior.CloseConn ection)
dlMusic.DataBind()
dlMusic.RepeatColumns = 2

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
6
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and...
8
by: drose0927 | last post by:
Please help! I can't get my program to exit if the user hits the Escape button: When I tried exit(EXIT_SUCCESS), it wouldn't compile and gave me this error: Parse Error, expecting `'}''...
5
by: Jesee | last post by:
I am reading Jeffrey Richter's book "Applied Microsoft .NET Framework programming",i came across "Exception handing". Page 405 says "If the stack overflow occurs within the CLR itself,your...
11
by: Scott C. Reynolds | last post by:
In VB6 you could do a SELECT CASE that would evaluate each case for truth and execute those statements, such as: SELECT CASE True case x > y: dosomestuff() case x = 5: dosomestuff() case y >...
2
by: Greg Corradini | last post by:
Hello All, A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among other things, both scripts create new tables, perform a query and then populate the tables with data in a...
6
by: redashley40 | last post by:
This is my first attempt in SQL and PreparedStatement I have add the PreparedStatement and I'm not to sure if I'm doing it correctly. When I do a test run on Choose 1 ,or 2 I get this error. Error...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
0
by: RCapps | last post by:
When running the below SQL Query I keep getting the following error: Server: Msg 4924, Level 16, State 1, Line 1 ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
2
by: kya2 | last post by:
I am not able to create following store procedure. CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT ) RESULT SETS 1 LANGUAGE SQL BEGIN part1 DECLARE TOTAL_LEFT INT DEFAULT 0; ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.