Connecting Tech Pros Worldwide Forums | Help | Site Map

MYSQL data fetching error using limit

donilourdu's Avatar
Member
 
Join Date: Jan 2007
Posts: 49
#1: May 9 '09
hi,
I am trying to retrive data from MYSQL database.I am using limit to fetch the data.It will fetch two rows instead of fetching ten rows.But when i try to debug it fetches eight rows instead of ten rows.The codes are given below for your reference.
Expand|Select|Wrap|Line Numbers
  1. private void data(string slimit,string elimit)
  2. {
  3. MySqlConnection conn = new MySqlConnection(ss);
  4. conn.Open();
  5. try
  6. {
  7. MySqlCommand cmd = new MySqlCommand("select iddocument from document_info where scanby is not null limit " + slimit + "," + elimit + ";" , conn);
  8. //cmd.Parameters.Add("?iddocument", MySqlDbType.VarChar).Value = aa;
  9. MySqlDataReader myread;
  10. myread = cmd.ExecuteReader();
  11. while (myread.Read())
  12. {
  13. f.log_insert(myread.GetString(0));
  14. }
  15. myread.Close();
  16. myread.Close();
  17. }
  18. catch (Exception ex)
  19. {
  20. MessageBox.Show(ex.Message);
  21. }
  22. finally
  23. {
  24.  conn.Close();
  25. }
With Regards,
Doni

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,727
#2: May 11 '09

re: MYSQL data fetching error using limit


Doni,

I'm confused. Should this be in the Access forum? This doesn't look like VBA code at all.

If you can say where this should be then I can move it there for you.
Denburt's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#3: May 13 '09

re: MYSQL data fetching error using limit


Looks like Javascript to me.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,727
#4: May 13 '09

re: MYSQL data fetching error using limit


I'll move it there pro tem.
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#5: May 13 '09

re: MYSQL data fetching error using limit


Quote:

Originally Posted by Denburt View Post

Looks like Javascript to me.

"public void " is JavaScript? its Java!

Java != JavaScript ... not even close.

OP,

I think you may be having trouble with understanding how the LIMIT function works.

In MySQL the first parameter is the number of the record to START from, the second is how many to display from there.

If you have ten records and said LIMIT 5,3 you would get record number 5 through 8. If you said LIMIT 10,10 you would get only one because counting from 10 there's only one record left (ie there is no 11,12,13...20)

If you're doing this for a pagation the first parameter should be page_number-1 * items_perPage.

so in your code subtract one from string, multiply it by estring and put this result as the first parameter and the number of records to display on a page as the second parameter.

Hope that makes enough sense. Try running some queries without code, from command line or the client to test it out.



Dan
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,727
#6: May 13 '09

re: MYSQL data fetching error using limit


Dan,

We're not from the dark-side you know. How you play with your coffee is your business.

Java / Javascript / whatever. They're all foreign languages to us over in Access. We would care, but you guys seem to have that well covered so why bother :D

I'll move it to Java for you.
Denburt's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#7: May 13 '09

re: MYSQL data fetching error using limit


LOL actually it says "private void" I missed that, at a quick glance thats what it appeared to be. I am also quite well aware that Java != JavaScript ... not even close. Thank you
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,940
#8: May 14 '09

re: MYSQL data fetching error using limit


I have £20 on it being C#. Any more bets?

Also, C# != Java != Javascript .. not even close ;)
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#9: May 14 '09

re: MYSQL data fetching error using limit


Expand|Select|Wrap|Line Numbers
  1. MessageBox.Show(ex.Message);
Yep, it's C# alright.
Reply