Subject: How to get "SELECT COUNT(*)" return information?
Posted By: datagram Post Date: 12/22/2004 9:57:34 AM
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

Reply By: stu9820 Reply Date: 12/22/2004 10:26:55 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(*)

Reply By: datagram Reply Date: 12/22/2004 1:31:37 PM
Yes, that worked!!  Now on another page if I wanted to display the data in the rows, that would be a Dataset right?

Reply By: nashnash Reply Date: 12/23/2004 12:21:12 AM

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

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

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


Go to topic 23938

Return to index page 680
Return to index page 679
Return to index page 678
Return to index page 677
Return to index page 676
Return to index page 675
Return to index page 674
Return to index page 673
Return to index page 672
Return to index page 671