Results 1 to 2 of 2

Thread: Count number of records...

  1. #1
    Member
    Join Date
    Dec 09
    Posts
    62

    Count number of records...

    I am at a loss here... (Visual Studio 2012 VB, MSSQL 2008)

    Is there a way to count the number of records in a sqldatasource without displaying a grid on my page?

    Code:
    <asp:SqlDataSource ID="sqlMessages" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" SelectCommand="SELECT * FROM [Messages] WHERE ([SentTo] = @SentTo) ORDER BY [MessageDate] DESC">
          <SelectParameters>
                 <asp:SessionParameter Name="SentTo" SessionField="MemberID" Type="Int32" />
          </SelectParameters>
    </asp:SqlDataSource>
    How can I get the number of records that are returned? another question I have a field "MessageStatus" how can I get the number or records that are listed as "new" as well... Here is what I would like to display...

    lblMessages.text = "Total Message: " WHAT DO I PUT HERE "Total New Messages: " WHAT DO I PUT HERE????
    Last edited by acrow; Sep 22nd, 2012 at 02:49 PM.

  2. #2
    King of sapila
    Join Date
    Oct 06
    Location
    Greece
    Posts
    3,508

    Re: Count number of records...

    Why don't u use MSSQL with a good ol stored procedure?You have it installed anyway.It may be done i sqldatasource but i would urge you not to use this control.Also don't use "*" for selecting data, use the columns names.
    The "as new" question, is blurry.What do you define as new?If you define a column named as messagestatus in sql then you can "select blah, form tableblah WHERE [SentTo] = @SentTo and messagestatus=1 order by etc etc.
    Assuming that when messagestatus gets the number 1 then it's a new message,or unread message or something.
    Slow as hell.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •