p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   How to get "SELECT COUNT(*)" return information? (http://p2p.wrox.com/showthread.php?t=22971)

datagram December 22nd, 2004 10:57 AM

How to get "SELECT COUNT(*)" return information?
 
Here is a part of my code...

Me.SqlCommand1.Connection = Me.SqlConnection1
SqlConnection1.Open()
Me.SqlCommand1.CommandText = "SELECT COUNT(*) AS in_process FROM tbl_current_call_list WHERE repname ='" & repname & "' AND in_process='yes'"

What do I use to see just the number of rows its returning? A reader or dataset or something? I just want to be able to see the number of rows, not any of the information.
Thank you


stu9820 December 22nd, 2004 11:26 AM

You can try this:

    Dim strSQL As String
    Dim strCOUNT As String
    Dim objCommand As New OleDbCommand

    objCommand.Connection = objConn
    strSQL = "SELECT COUNT(*) AS in_process FROM tbl_current_call_list WHERE repname ='" & repname & "' AND in_process='yes'"
    objCommand.CommandText = strSQL
    objCommand.CommandType = CommandType.Text

    objConn.Open()
    strCOUNT = CType(objCommand.ExecuteScalar, String)
    objConn.Close()


strCOUNT will hold the value of the COUNT(*)


datagram December 22nd, 2004 02:31 PM

Yes, that worked!! Now on another page if I wanted to display the data in the rows, that would be a Dataset right?


nashnash December 23rd, 2004 01:21 AM


that can be datareader or dataset depends upon your requirement.
like this

--DataReader------------------
SqlDataReader myReader = CommandName.ExecuteReader(CommandBehavior.Sequenti alAccess);

while (myReader.Read())
{
  Response.write(myReader["Columnanme"].toString());
}
myReader.Close()

---Dataset----
Dataset ds=new Dataset();
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from stock",connection object);
cmd1.Fill(ds,"stock");

now your dataset is filled with records.You can just bind to any controls.

Thanks
Nash



All times are GMT -4. The time now is 05:10 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.