ASP.net Help solve problem

Thanks.

I've tested the query and it's working. Can't get anything to display now i've also added the UserName parameter though.

Code:
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim inDate As DateTime
        Dim WeekNumber As Integer
        Dim UserName As String

        inDate = Date.Today.Date

        WeekNumber = Weeknumber_Entire4DayWeekRule(inDate)
        UserName = Me.User.Identity.Name

        Dim hoursAdapter As New ManHoursTableAdapters.tblHoursTableAdapter()
        Dim weeksHours As ManHours.tblHoursDataTable = hoursAdapter.GetWeekly(WeekNumber, UserName)

        GridView1.DataSource = weeksHours
        GridView1.DataBind()


    End Sub

I really need to start thinking how I can get data to display like I said in the original post though...

SQL Query

Code:
SELECT     tblHours.*
FROM         tblHours
WHERE DATEPART (dw, Date) is not null AND DATEPART (wk, Date) = @WeekNo 

AND UserName = @UserName
 
Still got the same problem, i've tried doing this another way as well..

Code:
 Protected Sub ObjectDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource1.Selecting
        Dim inDate As DateTime
        Dim WeekNumber As Integer
        Dim UserName As String

        inDate = Date.Today.Date

        WeekNumber = Weeknumber_Entire4DayWeekRule(inDate)
        UserName = Me.User.Identity.Name

        e.InputParameters("UserName") = UserName
        e.InputParameters("WeekNo") = WeekNumber
    End Sub[/B]

When I load the page using this method instead I get the error:

Code:
Object of type 'System.Int32' cannot be converted to type 'System.Decimal'.

Thanks for any help :)
 
You say you tested the query before, did you test it with the username parameter?

If so, and it worked you should check to see what is being stored in the UserName variable.
Debug through it, and find out what Me.User.Identity.Name is bringing back for the UserName variable.
 
The UserName variable is getting the correct user name.

I've tested the query in the dataset by typing the current week number and the user name i'm logging in with and getting results.

I can't see any problem with my coding either, although something is obviously wrong with the second attempt because of the error i'm getting.
 
In your second attempt the only integer I can see is for WeekNumber.

What is the data type of the returned value from your function?
 
Function outputs an Integer, here's the code:

Code:
 Private Function Weeknumber_Entire4DayWeekRule(ByVal inDate As DateTime) As Integer
        Const JAN As Integer = 1
        Const DEC As Integer = 12
        Const LASTDAYOFDEC As Integer = 31
        Const FIRSTDAYOFJAN As Integer = 1
        Const THURSDAY As Integer = 4
        Dim ThursdayFlag As Boolean = False

        ' Get the day number since the beginning of the year
        Dim DayOfYear As Integer = inDate.DayOfYear

        ' Get the numeric weekday of the first day of the
        ' year (using sunday as FirstDay)
        Dim StartWeekDayOfYear As Integer = _
           DirectCast(New DateTime(inDate.Year, JAN, FIRSTDAYOFJAN).DayOfWeek, Integer)
        Dim EndWeekDayOfYear As Integer = _
            DirectCast(New DateTime(inDate.Year, DEC, LASTDAYOFDEC).DayOfWeek, Integer)

        ' Compensate for the fact that we are using monday
        ' as the first day of the week
        If StartWeekDayOfYear = 0 Then
            StartWeekDayOfYear = 7
        End If
        If EndWeekDayOfYear = 0 Then
            EndWeekDayOfYear = 7
        End If

        ' Calculate the number of days in the first and last week
        Dim DaysInFirstWeek As Integer = 8 - StartWeekDayOfYear
        Dim DaysInLastWeek As Integer = 8 - EndWeekDayOfYear

        ' If the year either starts or ends on a thursday it will have a 53rd week
        If StartWeekDayOfYear = THURSDAY OrElse EndWeekDayOfYear = THURSDAY Then
            ThursdayFlag = True
        End If

        ' We begin by calculating the number of FULL weeks between the start of the year and
        ' our date. The number is rounded up, so the smallest possible value is 0.
        Dim FullWeeks As Integer = _
            CType(Math.Ceiling((DayOfYear - DaysInFirstWeek) / 7), Integer)

        Dim WeekNumber As Integer = FullWeeks

        ' If the first week of the year has at least four days, then the actual week number for our date
        ' can be incremented by one.
        If DaysInFirstWeek >= THURSDAY Then
            WeekNumber = WeekNumber + 1
        End If

        ' If week number is larger than week 52 (and the year doesn't either start or end on a thursday)
        ' then the correct week number is 1.
        If WeekNumber > 52 AndAlso Not ThursdayFlag Then
            WeekNumber = 1
        End If

        'If week number is still 0, it means that we are trying to evaluate the week number for a
        'week that belongs in the previous year (since that week has 3 days or less in our date's year).
        'We therefore make a recursive call using the last day of the previous year.
        If WeekNumber = 0 Then
            WeekNumber = Weeknumber_Entire4DayWeekRule( _
                New DateTime(inDate.Year - 1, DEC, LASTDAYOFDEC))
        End If
        Return WeekNumber
    End Function
 
I can't tell. It doesn't break on a line it just fails to load the page.

I tried debugging by stepping over each line but the page doesn't fail when I do that. It just fails when I try load it without debugging.
 
Ok i've got that part working, now for the difficult part that i've got no idea about.

How can I get the results to display like

----- Mon Tue Wed Thu Fri Sat Sun TimeCode

---------6----3---4----3---1-------------321--
---------4----2---1----4---3-------------890--
---------6----3---2----5---2-------------321--

Any ideas? It's a lot easier for the user if I can display the data in a weekly breakdown like that.

All the numbers represent the number of hours spend on a TimeCode.
 
You hero, unfortunately I can't check my hotmail from work so i'll make sure I give you a shout when I get home.

Thanks a lot Stelly!
 
Is there any chance of posting the code up on here Stelly or e-mailing me it to my work address so I can have a look?

Big thanks again :)
 
Back
Top Bottom