Calendar Rendering

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ajaymehra

    Calendar Rendering


    Hi,
    Im using a calendar control and on the dayrender event - I call m
    sub, which runs a query and gets a SUM value for each day. Below is th
    code

    ----------------------------------------------------

    Public Sub calhours_dayren der(ByVal s As Object, ByVal e A
    DayRenderEventA rgs)

    Dim calCell As TableCell
    Dim DayHours As String
    Dim DayDate As Date
    Dim Conn As SqlConnection = Ne
    SqlConnection(" Server=CHRI_010 01; Initial Catalog=ELY3019 ; uid=mmapp
    password=pwd")

    DayDate = e.Day.Date

    calCell = e.Cell

    Dim sqlComm As SqlCommand
    Dim sqlDR As SqlDataReader

    Conn.Open()

    sqlComm = New SqlCommand("Sel ect Convert(int
    Sum(Round(Hours ,0))) as Hours From GetHoursForDays ('10314', '"
    DayDate & "', '" & DayDate & "')", Conn)

    sqlDR = sqlComm.Execute Scalar()

    DayHours = CType(sqlDR("Ho urs"), String)
    'DayHours = CType(sqlDR(0), String)

    Conn.Close()

    calCell.Control s.Add(New LiteralControl( "<p><font color=whit
    size=1>"))

    calCell.Control s.Add(New LiteralControl( DayHours))

    End Sub

    ----------------------------------------------------

    I keep getting this error :

    Specified cast is not valid.
    Description: An unhandled exception occurred during the execution o
    the current web request. Please review the stack trace for mor
    information about the error and where it originated in the code.

    Exception Details: System.InvalidC astException: Specified cast is no
    valid.

    Source Error:

    Line 54: sqlDR = sqlComm.Execute Scalar()



    Any ideas ??

    ajaymehr
    -----------------------------------------------------------------------
    Posted via http://www.mcse.m
    -----------------------------------------------------------------------
    View this thread: http://www.mcse.ms/message390078.htm

  • Teemu Keiski

    #2
    Re: Calendar Rendering

    Hi,

    ExecuteScalar method returns a single value (first column, first row from
    the query results) , and you are trying to assign that to sqlDr which is of
    type SqlDataReader. Therefore the code fails. If you want to return a
    DataReader, call ExecuteReader instead. If you want to get the value with
    ExecuteScalar, assign the return value to variable of correct type
    (straight to string with casting for example)

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    "ajaymehra" <ajaymehra.11ko yu@mail.mcse.ms > wrote in message
    news:ajaymehra. 11koyu@mail.mcs e.ms...

    Hi,
    Im using a calendar control and on the dayrender event - I call my
    sub, which runs a query and gets a SUM value for each day. Below is the
    code

    ----------------------------------------------------

    Public Sub calhours_dayren der(ByVal s As Object, ByVal e As
    DayRenderEventA rgs)

    Dim calCell As TableCell
    Dim DayHours As String
    Dim DayDate As Date
    Dim Conn As SqlConnection = New
    SqlConnection(" Server=CHRI_010 01; Initial Catalog=ELY3019 ; uid=mmapp;
    password=pwd")

    DayDate = e.Day.Date

    calCell = e.Cell

    Dim sqlComm As SqlCommand
    Dim sqlDR As SqlDataReader

    Conn.Open()

    sqlComm = New SqlCommand("Sel ect Convert(int,
    Sum(Round(Hours ,0))) as Hours From GetHoursForDays ('10314', '" &
    DayDate & "', '" & DayDate & "')", Conn)

    sqlDR = sqlComm.Execute Scalar()

    DayHours = CType(sqlDR("Ho urs"), String)
    'DayHours = CType(sqlDR(0), String)

    Conn.Close()

    calCell.Control s.Add(New LiteralControl( "<p><font color=white
    size=1>"))

    calCell.Control s.Add(New LiteralControl( DayHours))

    End Sub

    ----------------------------------------------------

    I keep getting this error :

    Specified cast is not valid.
    Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code.

    Exception Details: System.InvalidC astException: Specified cast is not
    valid.

    Source Error:

    Line 54: sqlDR = sqlComm.Execute Scalar()



    Any ideas ???


    ajaymehra
    ------------------------------------------------------------------------
    Posted via http://www.mcse.ms
    ------------------------------------------------------------------------
    View this thread: http://www.mcse.ms/message390078.html


    Comment

    • ajaymehra

      #3
      Re: Calendar Rendering


      thanks - it works now
      Teemu Keiski wrote:[color=blue]
      > *Hi,
      >
      > ExecuteScalar method returns a single value (first column, first ro
      > from
      > the query results) , and you are trying to assign that to sqlDr whic
      > is of
      > type SqlDataReader. Therefore the code fails. If you want to retur
      > a
      > DataReader, call ExecuteReader instead. If you want to get the valu
      > with
      > ExecuteScalar, assign the return value to variable of correct type
      > (straight to string with casting for example)
      >
      > --
      > Teemu Keiski
      > MCP, Microsoft MVP (ASP.NET), AspInsiders member
      > ASP.NET Forum Moderator, AspAlliance Columnist
      >
      > "ajaymehra" <ajaymehra.11ko yu@mail.mcse.ms > wrote in message
      > news:ajaymehra. 11koyu@mail.mcs e.ms...
      >
      > Hi,
      > Im using a calendar control and on the dayrender event - I call my
      > sub, which runs a query and gets a SUM value for each day. Below i
      > the
      > code
      >
      > ----------------------------------------------------
      >
      > Public Sub calhours_dayren der(ByVal s As Object, ByVal e As
      > DayRenderEventA rgs)
      >
      > Dim calCell As TableCell
      > Dim DayHours As String
      > Dim DayDate As Date
      > Dim Conn As SqlConnection = New
      > SqlConnection(" Server=CHRI_010 01; Initial Catalog=ELY3019
      > uid=mmapp;
      > password=pwd")
      >
      > DayDate = e.Day.Date
      >
      > calCell = e.Cell
      >
      > Dim sqlComm As SqlCommand
      > Dim sqlDR As SqlDataReader
      >
      > Conn.Open()
      >
      > sqlComm = New SqlCommand("Sel ect Convert(int,
      > Sum(Round(Hours ,0))) as Hours From GetHoursForDays ('10314', '" &
      > DayDate & "', '" & DayDate & "')", Conn)
      >
      > sqlDR = sqlComm.Execute Scalar()
      >
      > DayHours = CType(sqlDR("Ho urs"), String)
      > 'DayHours = CType(sqlDR(0), String)
      >
      > Conn.Close()
      >
      > calCell.Control s.Add(New LiteralControl( "<p><font color=white
      > size=1>"))
      >
      > calCell.Control s.Add(New LiteralControl( DayHours))
      >
      > End Sub
      >
      > ----------------------------------------------------
      >
      > I keep getting this error :
      >
      > Specified cast is not valid.
      > Description: An unhandled exception occurred during the execution of
      > the current web request. Please review the stack trace for more
      > information about the error and where it originated in the code.
      >
      > Exception Details: System.InvalidC astException: Specified cast i
      > not
      > valid.
      >
      > Source Error:
      >
      > Line 54: sqlDR = sqlComm.Execute Scalar()
      >
      >
      >
      > Any ideas ???
      >
      >
      > ajaymehra
      > ------------------------------------------------------------------------
      > Posted via http://www.mcse.ms
      > ------------------------------------------------------------------------
      > View this thread: http://www.mcse.ms/message390078.html[/color]

      ajaymehr
      -----------------------------------------------------------------------
      Posted via http://www.mcse.m
      -----------------------------------------------------------------------
      View this thread: http://www.mcse.ms/message390078.htm

      Comment

      Working...