By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

MYSQL data fetching error using limit

donilourdu
P: 53
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
May 9 '09 #1
Share this Question
Share on Google+
11 Replies


NeoPa
Expert Mod 15k+
P: 31,494
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.
May 11 '09 #2

Denburt
Expert 100+
P: 1,356
Looks like Javascript to me.
May 13 '09 #3

NeoPa
Expert Mod 15k+
P: 31,494
I'll move it there pro tem.
May 13 '09 #4

dlite922
Expert 100+
P: 1,584
@Denburt
"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
May 13 '09 #5

NeoPa
Expert Mod 15k+
P: 31,494
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.
May 13 '09 #6

Denburt
Expert 100+
P: 1,356
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
May 13 '09 #7

Markus
Expert 5K+
P: 6,050
I have 20 on it being C#. Any more bets?

Also, C# != Java != Javascript .. not even close ;)
May 14 '09 #8

10K+
P: 13,264
Expand|Select|Wrap|Line Numbers
  1. MessageBox.Show(ex.Message);
Yep, it's C# alright.
May 14 '09 #9

donilourdu
P: 53
@donilourdu
I solved the issue
Jun 21 '10 #10

NeoPa
Expert Mod 15k+
P: 31,494
I'm pleased to hear it Doni.

Perhaps you wouldn't mind posting your solution now you have one.
Jun 21 '10 #11

donilourdu
P: 53
@NeoPa
Denburt is correct. I wrongly undestand the concepts. Extremly sorry man for so much of delay.
Jul 1 '10 #12

Post your reply

Sign in to post your reply or Sign up for a free account.