Hi I urgantly need some help
I have a RadGrid with myltiple Fields of which 2 is DateTimeColumns
I use the NeedDataSource to get data from a DataTable in the Database.
I need the EndDate Column to be able to Take nulls and Display Nulls When Returned from Database.
I can Insert Send Null Values To the Database When Inserting. But When I Need to Get The Null Date Back From The Database
I keep getting the Error: Specified cast is not valid. regarding the DateTime of EndDate.
This is my Form Code:
This is my Code Behind part one.
This is my Code Behind For My DataEntity
Any Advice on why I keep Getting the Error and how I might be able to Fix it.
I have a RadGrid with myltiple Fields of which 2 is DateTimeColumns
I use the NeedDataSource to get data from a DataTable in the Database.
I need the EndDate Column to be able to Take nulls and Display Nulls When Returned from Database.
I can Insert Send Null Values To the Database When Inserting. But When I Need to Get The Null Date Back From The Database
I keep getting the Error: Specified cast is not valid. regarding the DateTime of EndDate.
This is my Form Code:
<
telerik:RadGrid
ID
=
"rgParameters"
runat
=
"server"
AutoGenerateDeleteColumn
=
"True"
AutoGenerateEditColumn
=
"True"
AlternatingItemStyle-BackColor
=
"white"
GridLines
=
"None"
GroupingEnabled
=
"False"
Width
=
"100%"
Height
=
"500px"
AutoGenerateColumns
=
"False"
ondeletecommand
=
"rgParameters_DeleteCommand"
oninsertcommand
=
"rgParameters_InsertCommand"
onneeddatasource
=
"rgParameters_NeedDataSource"
onupdatecommand
=
"rgParameters_UpdateCommand"
oniteminserted
=
"rgParameters_ItemInserted"
>
<
AlternatingItemStyle
BackColor
=
"White"
/>
<
MasterTableView
Caption
=
"Parameters"
CommandItemDisplay
=
"TopAndBottom"
DataKeyNames
=
"ScheduleParaID,StartDate,EndDate,WeekScheduled,WEPHScheduled"
ShowFooter
=
"true"
>
<
Columns
>
<
telerik:GridBoundColumn
AllowFiltering
=
"False"
AllowSorting
=
"False"
DataField
=
"ScheduleParaID"
HeaderText
=
"ScheduleParaID"
ReadOnly
=
"true"
UniqueName
=
"ScheduleParaID"
Visible
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridDateTimeColumn
AllowFiltering
=
"False"
DataField
=
"StartDate"
HeaderText
=
"Start Date"
UniqueName
=
"StartDate"
DataFormatString
=
"{0:dd/MM/yyyy}"
>
</
telerik:GridDateTimeColumn
>
<
telerik:GridDateTimeColumn
AllowFiltering
=
"False"
DataField
=
"EndDate"
HeaderText
=
"End Date"
UniqueName
=
"EndDate"
DataFormatString
=
"{0:dd/MM/yyyy}"
Reorderable
=
"True"
>
</
telerik:GridDateTimeColumn
>
<
telerik:GridNumericColumn
AllowFiltering
=
"False"
DataField
=
"WeekScheduled"
HeaderText
=
"Trains Scheduled (Week Days)"
UniqueName
=
"WeekScheduled"
AllowRounding
=
"False"
>
</
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
AllowFiltering
=
"False"
DataField
=
"WEPHScheduled"
HeaderText
=
"Train Scheduled (WE and Public Holidays)"
UniqueName
=
"WEPHScheduled"
AllowRounding
=
"False"
>
</
telerik:GridNumericColumn
>
</
Columns
>
<
EditFormSettings
EditFormType
=
"AutoGenerated"
></
EditFormSettings
>
</
MasterTableView
>
</
telerik:RadGrid
>
This is my Code Behind part one.
protected
void
rgParameters_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
TrainOperationParameters tparam =
new
TrainOperationParameters();
rgParameters.DataSource = tparam.Select();
tparam =
null
;
}
This is my Code Behind For My DataEntity
[DataObjectMethod(DataObjectMethodType.Select,
true
)]
public
List<TrainOperationParameters> Select()
{
List<TrainOperationParameters> list =
new
List<TrainOperationParameters>();
DataTable dt;
try
{
dt = DataMethods.ReturnMultipleRowResultSet(
"[IM].[GetTrainOpParameters]"
, String.Empty);
if
(dt.Rows.Count > 0)
{
foreach
(DataRow dr
in
dt.Rows)
{
TrainOperationParameters param =
new
TrainOperationParameters();
param.ScheduleParaID = Convert.ToInt32(dr[
"TrainOpParaID"
]);
param.StartDate = (DateTime)dr[
"StartDate"
];
param.EndDate = ((DateTime)dr[
"EndDate"
]);
param.WeekScheduled = Convert.ToInt32(dr[
"WeekScheduled"
]);
param.WEPHScheduled = Convert.ToInt32(dr[
"WEPHScheduled"
]);
list.Add(param);
}
}
}
catch
(Exception)
{
throw
;
}
finally
{
dt =
null
;
}
return
list;
}
Any Advice on why I keep Getting the Error and how I might be able to Fix it.