?
Solved

SQL table count

Posted on 2006-10-26
5
Medium Priority
?
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:K V
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:K V
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:
K V earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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 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…

762 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