Setting a DateTime Field to Blank

Hi All,

I’m trying to set a DateTime field to blank but can’t seem to work out how to do it.

Any ideas?

Here is the code I’ve been working with.

private void UD100Form_BeforeToolClick(object sender, Ice.Lib.Framework.BeforeToolClickEventArgs args)
	{
		
		switch (args.Tool.Key)
		{
			case "PrintTool":
				if (this.txtKeyField.Text == string.Empty)
				{
					EpiMessageBox.Show("You need a Load Number");
					return;
				}
					LaunchFormOptions lfo = new LaunchFormOptions();
					lfo.IsModal = false;
					lfo.ContextValue = this.txtKeyField.Text;
					ProcessCaller.LaunchForm(oTrans, "OMRM001", lfo);
				break;
			case "ToolBtnUnlockSales":
				if (!string.IsNullOrEmpty(edvUD100.dataView[edvUD100.Row]["EstimatedDateMth_c"].ToString()) && ((DateTime?)edvUD100.dataView[edvUD100.Row]["EstimatedStampDate_c"]).HasValue)
				{
					DialogResult dialogResult = EpiMessageBox.Show("Are you sure you want to unlock Sales? This will clear the information!","Sales Unlock", MessageBoxButtons.YesNo);
					if (dialogResult == DialogResult.Yes)
					{
						edvUD100.dataView.Table.Rows[0]["AcctsConfirm_c"] = false;
						edvUD100.dataView.Table.Rows[0]["EstimatedDateMth_c"] = string.Empty;
						//edvUD100.dataView.Table.Rows[0]["EstimatedStampDate_c"] = default(DateTime);
						edvUD100.dataView.Table.Rows[0]["EstimatedStamp_c"] = string.Empty;
						epiShape_SalesOffice.Visible = false;
						return;
					}
					EpiMessageBox.Show ("There is no data for me");
				}

				break;

I’ve commented it out at the moment as it’s causing massive issues, any thoughts? The field name is EstimatedStampDate_c but there is others that use Date format.

Kind regards,
Aaron.

A “blank” date should be the value null. Try doing:

edvUD100.dataView.Table.Rows[0]["EstimatedStampDate_c"] = null;

You can’t null a date field I don’t believe…

image

1 Like

Could of just used, DBNull.Value.

Sorry for this pointless post…

I think that’s the most helpful error message I’ve ever seen…

I thought that was as well… Normally they’re like riddles… :smiley:

1 Like