how to count sql row...

Discussion in 'Questions (Windows Mobile)' started by belotrei, Jun 3, 2007.

  1. belotrei

    belotrei Member

    I want to show the total of my record from sql database. (just 1 column, xxxxx records/row)

    I used this :

    Cmd.CommandText = "SELECT COUNT(column) FROM tablename"
    Reader.Value = Cmd.ExecuteReader
    msgbox (reader.value)

    Why it always gave me empty string?

    May i miss something?

    Thanks guys, this forum is really helpful! :sign0060:
  2. Erel

    Erel Administrator Staff Member Licensed User

    You are missing two things:
    1 - You need to first read the data using Reader.ReadNextRow.
    2 - You should get the data using Reader.GetValue.

    Cmd.CommandText = "SELECT COUNT(*) FROM orders"
    Reader.Value = cmd.ExecuteReader
  3. belotrei

    belotrei Member

    Thank you so much Erel! I just feel like idiot... :eek:
  4. Erel

    Erel Administrator Staff Member Licensed User

    It took me some thinking too, you should feel just fine ;)
  5. nightlyfe

    nightlyfe Member

    But I feel like an idiot...

    I keep getting an error when I try to put this in a Sub. It's an "Object reference not set to an instance of an object" error.
    I know I'm missing something obvious, but I have no idea what.
    Care to give a noob a boost?

    UPDATE: I figured it out. Using the following code, I was able to get rid of the error:

    Command.CommandText = "Select COUNT(*) FROM table"
    Reader.Value = command.ExecuteReader

    Thanks for the pointers on the way.
    Last edited: Oct 8, 2009
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice