5 Replies - 3708 Views - Last Post: 19 September 2010 - 08:15 AM Rate Topic: -----

#1 whitekeeper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-July 09

Show 8 records from Database from a comboBox selection

Posted 13 September 2010 - 09:15 AM

I know how to display the latest records from database but only one row of record.

This is what i'm trying to accomplished.

I want to display 8 rows of records from database, when a combo Box selection is done. When a user make one of the selection in the comboBox, 8 rows of records will be shown that is related to the selection made.

I need this to work so that i can display latest 8 records or previous 8 records based on what i select in the comboBox.

Any ideas that i can use to complete this? All help appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Show 8 records from Database from a comboBox selection

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Show 8 records from Database from a comboBox selection

Posted 13 September 2010 - 09:20 AM

Most databases aren't really sequential so saying "latest" entries doesn't help much.
You'll need to include a date & time field for when the entry was created/edited and then run your query, then sort the results and take the 'latest' based on those fields.
Was This Post Helpful? 3
  • +
  • -

#3 whitekeeper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-July 09

Re: Show 8 records from Database from a comboBox selection

Posted 13 September 2010 - 09:38 AM

Hi there, thanks for that but i'm not trying to use date & time to display the latest records. Rather, i'm trying to count the total row that i have in my database (sql server compact edition), then take that value subtracted by 1 to display the latest row. This only display one row. I have a 'previous' & 'current' selection in my combo box whereby 'previous' will show the first existing 8 records and 'current' will show the latest 8 records or less than that.

Thank you. Hope u can help.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Show 8 records from Database from a comboBox selection

Posted 13 September 2010 - 09:48 AM

Quote

Rather, i'm trying to count the total row that i have in my database (sql server compact edition), then take that value subtracted by 1 to display the latest row.

I hope you never have to work with indexed tables then, because that won't work.

DB tables aren't like Excel files. They aren't always stored in a FIFO pattern. That's why SQL has WHERE and ORDER BY.

Anyway, if you are using Microsoft Sql Server, you can use TOP to limit your query to a specific number of rows. For example:
SELECT TOP 8 * FROM table ORDER BY dateTimeColumn DESC

Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Show 8 records from Database from a comboBox selection

Posted 14 September 2010 - 04:36 AM

If you don't have a Date/Time field in the table, how about a numeric field that is being incremented for each record(like an identity seed)? You could use that to get the "latest".

SELECT TOP 8 * FROM Table1 ORDER BY IDColumn DESC


Was This Post Helpful? 2
  • +
  • -

#6 whitekeeper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-July 09

Re: Show 8 records from Database from a comboBox selection

Posted 19 September 2010 - 08:15 AM

Thanks everyone for helping me. Problem solved.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1