Solved

SQL table count

Posted on 2006-10-26
5
227 Views
Last Modified: 2010-04-16
im am trying to count the table mark_db, but when i run it it only returns a message where it says "false", what is wrong, i would like if you cut help me so it returns a number instead.

        Dim cmd As New Data.SqlServerCe.SqlCeCommand
        cmd.CommandText = "SELECT COUNT(*) AS row_count FROM mark_db"
        cmd.Connection = form1.ssceconn
        Dim rdr As Data.SqlServerCe.SqlCeDataReader
        rdr = cmd.ExecuteReader
        rdr.Read()
        Dim count_tbl1 As String
        count_tbl1 = rdr.Read.ToString
        MsgBox(count_tbl1)
0
Comment
Question by:mSchmidt
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:theGhost_k8
Comment Utility
data. .Read() will return true as long as there is an additional row to be read.
so as "SELECT COUNT(*) AS row_count FROM mark_db" has only one record,
the first time you are writing
        rdr.Read() the result is "scanned" and now there is no more result.
Reading more will return FALSE . and thats what you are getting in message box.
try this
        MsgBox(rdr.Read().tostring)
0
 
LVL 21

Expert Comment

by:theGhost_k8
Comment Utility
i mean DO THIS...
        Dim cmd As New Data.SqlServerCe.SqlCeCommand
        cmd.CommandText = "SELECT COUNT(*) AS row_count FROM mark_db"
        cmd.Connection = form1.ssceconn
        Dim rdr As Data.SqlServerCe.SqlCeDataReader
        rdr = cmd.ExecuteReader
        MsgBox(rdr.Read().tostring)        
         
0
 

Author Comment

by:mSchmidt
Comment Utility
hmm, it just keep saying true now, still no number,
any other ideas?
0
 
LVL 21

Accepted Solution

by:
theGhost_k8 earned 500 total points
Comment Utility
oouch !! sorry i;ve written worng.. u have to read data from reader not return value..
use
rdr.GetValue(0).ToString
0
 

Author Comment

by:mSchmidt
Comment Utility
thx
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
allStar challenge 1 40
parentbit challenge 3 50
topping1 challenge 7 46
Non-recursive backtracking, using a stack 1 43
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now