-4

I just want who many number of record comes against specific query, nothing else. for example select count(column name) from table answer = 15

  Dim cmd As SqlCommand = New SqlCommand("SELECT  qnumber," + item + " FROM tencmpC1", cc) 
            Dim adp As New SqlDataAdapter(cmd)
            cmd.Connection.Open()


            Dim oleRdr As SqlDataReader = cmd.ExecuteReader
            'txt1.Text = oleRdr.HasRows

                oleRdr.Read()
                Dim count As Integer
                While oleRdr.Read()
                    count = count + 1
                End While
                txt1.Text = count


            oleRdr.Close()

I try this code to get number of rows from query but failed to get. Please give me piece of code, anyone.

1
  • please answer this question if you understand know? Commented May 30, 2015 at 15:25

1 Answer 1

-1
Dim cmd As SqlCommand = New SqlCommand("SELECT  qnumber," + item + " FROM tencmpC1", cc)
Dim adp As New SqlDataAdapter(cmd)
cmd.Connection.Open()
Dim ds As new Data.Dataset 
Dim dt as new Data.DataTable
adp.Fill(ds)
dt=ds.Tables(0)
Dim count as Integer=dt.Rows.Count    
Sign up to request clarification or add additional context in comments.

2 Comments

Dear mahadev error arises Cannot find table 0. stackoverflow.com/users/1662394/mahadev
@WaqasAli If the answer doesn't answer your question, please don't accept it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.