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

MYSQL data fetching error using limit

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

Expert Mod 15k+
P: 31,770

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

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

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

Expert 100+
P: 1,584
"public void " is JavaScript? its Java!

Java != JavaScript ... not even close.


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.

May 13 '09 #5

Expert Mod 15k+
P: 31,770

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

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

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

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

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

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

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

P: 53
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.