Solved

SQL table count

Posted on 2006-10-26
5
232 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: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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

738 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