Solved

SQL table count

Posted on 2006-10-26
5
229 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
ID: 17810005
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
ID: 17810007
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
ID: 17810136
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
ID: 17810350
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
ID: 17810403
thx
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
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…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

785 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