在存储库上存储空日期时出错

时间:2016-09-01 07:21:11

标签: c# winforms devexpress

如何在存储库组合框中放置一个null,其中数据类型是日期时间? 或者我应该将日期时间转换为null? 我试着把这段代码给我错误

public void store()
{

 GridView view = sender as GridView;
 for (int i = 0; i < gridView1.RowCount; i++)
            {
 if (gridView1.GetDataRow(i)["signOut"] == DBNull.Value)
            {           
                DateTime? px = null;

                if (!repositoryItemComboBox10.Items.Contains(px))
                {
                    repositoryItemComboBox10.Items.Add(px);
                }
            }
}
}

image error1

其他catch

中的选择查询错误为method
  public void SDB()
    {
        SqlDataAdapter adapter2 = new SqlDataAdapter(command.CommandText, myConnection);
        try
        {
            ds2.Clear();
            dt2.Clear();
            command2.Connection = myConnection;
            command2.CommandText = " ..."
            adapter2.SelectCommand = command2;

            adapter2.Fill(ds2);
            adapter2.Fill(dt2);
            gridControl1.DataSource = dt2;

            myConnection.Open();

        }
        catch (Exception ex)
        {
            MessageBox.Show("error" + ex);
        }
        finally
        {
            myConnection.Close();
        }

结论我想要的是获取过滤器,如果注销为空或空 image that i want

1 个答案:

答案 0 :(得分:0)

错误是因为您无法将null直接指定给日期。您可以按如下方式创建可以为空的日期

DateTime? px = (DateTime?)null;