I want to display the number of records for each state in a database. I'm using a strongly types dataset. In my method, I have the following
SELECT COUNT(ID) AS iTotal, STATE
FROM members
WHERE (Suspend = 0)
GROUP BY STATE
ORDER BY STATE
In the code behind of my page I have
Dim mateAdapter As New WAPTableAdapters.membersTableAdapter
Dim mates As WAP.membersDataTable
Dim mate As WAP.membersRow
mates = mateAdapter.GetDataState
For Each mate In mates
Select Case mate.STATE
Case "AK"
LabelAK.Text = mate.ID.
End Select
Next
What shouldLabelAK.Text = mate.ID. be for me to be able to display the number of records that have 'AK' in the state field?
Diane
I think if you use
LabelAK.Text = mate.iTotal
you'll get what you're looking for.
|||That's what i thought, but it doesn't like it.
Description:Anerror occurred during the compilation of a resource required to servicethis request. Please review the following specific error details andmodify your source code appropriately.
Compiler Error Message:BC30456: 'iTotal' is not a member of 'WAP.membersRow'.
But it is in the dataset, and i can get a preview of the data in the dataset. But it doesn't like it in the page.
Diane
Try mate.iTotal.ToString
I had some state and zipcode data around so I put this together.
webform:
<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:Label id="LabelMO" runat="server" Text="Label"></asp:Label> </div> </form></body></html>
code behind:
Imports WAPTableAdaptersPartialClass TestInherits System.Web.UI.PageProtected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs) _Handles Me.LoadDim mateAdapterAs New ZipcodesTableAdapterDim matesAs WAP.ZipcodesDataTableDim mateAs WAP.ZipcodesRow mates = mateAdapter.GetDataStateFor Each mateIn matesSelect Case mate.StateCase"MO" LabelMO.Text = mate.iTotal.ToStringEnd Select Next End SubEnd Class
GetDataStat method:
selectcount(Zipcode)as iTotal, Statefrom ZipcodesGroup by StateOrder by State|||
I have exactly what you do, and I'm getting the error that iTotal is not a member of the row. There must be something I'm overlooking that I've got wrong. But when i compare mine with yours, I don't see a difference.
Diane
|||That is very odd, I know how you feel though. Sometimes what seems like it should be so easy is infuriatingly difficult.
Post your code so I can play around with it, or you can send it to me at eterry28 @. gmail . com
Thank youeterry28
I did post my code in the first post.
Diane
|||I resolved my problem by returning the state field in all rows and changing my code to Inmates.Compute("count(STATE)", "STATE='VT'").ToString
Thanks for your help
Diane
No comments:
Post a Comment