我尝试从LinqDataSource填充gridview。页面运行时出现此错误:
不能为System.DateTime类型的null成员,这是一个值类型,不能赋予空值。
我的错误在哪里?
.aspx的
<dx:ASPxDateEdit ID="dtTranferDateFirst" runat="server"
DisplayFormatString="dd.MM.yyyy dddd" ></dx:ASPxDateEdit>
<dx:ASPxButton ID="btnGetTransfers" runat="server" Text="Get Transfers"
OnClick="btnGetTransfers_Click"></dx:ASPxButton>
<dx:ASPxGridView ID="grdTransferOrder"....
.....
....
</dx:ASPxGridView>
<asp:LinqDataSource ID="lnqTransferOrder"
ContextTypeName="MyApp.Classes.ModelDataContext"
TableName="TransferOrders" EnableDelete="True" EnableInsert="True"
EnableUpdate="True"
runat="server" ondeleting="lnqTransferOrder_Deleting"
OnInserting="lnqTransferOrder_Inserting" OnUpdating="lnqTransferOrder_Updating"
Where="Statues==0" EntityTypeName="">
</asp:LinqDataSource>
C#
private DateTime dtLastDate = DateTime.MaxValue;
private void BindGrid()
{
this.lnqTransferOrder.Where = "DateScheduled >= DateTime.Parse(\"" +
this.dtTranferDateFirst.Date.ToString() + "\")&&DateScheduled <
DateTime.Parse(\"" + this.dtLastDate.Date.ToString() + "\") && Statues!=5";
this.grdTransferOrder.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!base.IsPostBack)
{
this.dtTranferDateFirst.Date = System.DateTime.Today;
}
this.dtLastDate = this.dtTranferDateFirst.Date.AddDays(1.0);
this.BindGrid();
}
protected void btnGetTransfers_Click(object sender, System.EventArgs e)
{
}
答案 0 :(得分:0)
我认为您正在尝试将包含可空日期时间列(dtTransferDateFirst)的表(TransferOrders)绑定到具有不可为空的datetime列的网格。尝试将表上的列设置为不可为空。