how to count sql row...

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:
 

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:

Connection.BeginTransaction
Command.CommandText = "Select COUNT(*) FROM table"
reader.New1
Reader.Value = command.ExecuteReader
Reader.ReadNextRow
Msgbox(reader.GetValue(0))
Reader.Close

Thanks for the pointers on the way.
 
Last edited:
Top