Calendar Rendering

A

ajaymehra

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_dayrender(ByVal s As Object, ByVal e A
DayRenderEventArgs)

Dim calCell As TableCell
Dim DayHours As String
Dim DayDate As Date
Dim Conn As SqlConnection = Ne
SqlConnection("Server=CHRI_01001; 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("Select Convert(int
Sum(Round(Hours,0))) as Hours From GetHoursForDays('10314', '"
DayDate & "', '" & DayDate & "')", Conn)

sqlDR = sqlComm.ExecuteScalar()

DayHours = CType(sqlDR("Hours"), String)
'DayHours = CType(sqlDR(0), String)

Conn.Close()

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

calCell.Controls.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.InvalidCastException: Specified cast is no
valid.

Source Error:

Line 54: sqlDR = sqlComm.ExecuteScalar()



Any ideas ??

ajaymehr
 
T

Teemu Keiski

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


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_dayrender(ByVal s As Object, ByVal e As
DayRenderEventArgs)

Dim calCell As TableCell
Dim DayHours As String
Dim DayDate As Date
Dim Conn As SqlConnection = New
SqlConnection("Server=CHRI_01001; 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("Select Convert(int,
Sum(Round(Hours,0))) as Hours From GetHoursForDays('10314', '" &
DayDate & "', '" & DayDate & "')", Conn)

sqlDR = sqlComm.ExecuteScalar()

DayHours = CType(sqlDR("Hours"), String)
'DayHours = CType(sqlDR(0), String)

Conn.Close()

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

calCell.Controls.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.InvalidCastException: Specified cast is not
valid.

Source Error:

Line 54: sqlDR = sqlComm.ExecuteScalar()



Any ideas ???


ajaymehra
 
A

ajaymehra

thanks - it works now
Teemu said:
*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


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_dayrender(ByVal s As Object, ByVal e As
DayRenderEventArgs)

Dim calCell As TableCell
Dim DayHours As String
Dim DayDate As Date
Dim Conn As SqlConnection = New
SqlConnection("Server=CHRI_01001; 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("Select Convert(int,
Sum(Round(Hours,0))) as Hours From GetHoursForDays('10314', '" &
DayDate & "', '" & DayDate & "')", Conn)

sqlDR = sqlComm.ExecuteScalar()

DayHours = CType(sqlDR("Hours"), String)
'DayHours = CType(sqlDR(0), String)

Conn.Close()

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

calCell.Controls.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.InvalidCastException: Specified cast i
not
valid.

Source Error:

Line 54: sqlDR = sqlComm.ExecuteScalar()



Any ideas ???


ajaymehra

ajaymehr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top