Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL table count

Posted on 2006-10-26
5
Medium Priority
?
237 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Progress

618 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