-1

I have DataTable with date column. I would like to know how to set default value of the column to current date without using loop.

I have check below code, but I would like to know what is "Value" in below code

var col = result.Columns.Add("Column1", typeof(CellObject));
col.DefaultValue = new CellObject { Value = null };

Updated Code2 :-

var col = ds1.Tables[0].Columns.Add("LastUpdatedDateTime", typeof(DateTime));
col.DefaultValue = DateTime.Today;
Packing
  • 17
  • 7

1 Answers1

0

Sorry ill try again.

Is CellObject a class you have defined? its doesn't appear in the docs for Datatable. DefaultValue takes an object.

From the context id assume .Value is a property in the CellObject class, and your constructor is setting it to null.

Have you tried

var col = result.Columns.Add("Column1", typeof(CellObject));
col.DefaultValue = new CellObject { Value = DateTime.UtcNow();};

That's assuming .Value is a datetime or variant.