I'm trying to store currant datetime in Datatable Datetime column using below code
dtRow["dCurrantDate"] = DateTime.Now;
but getting this error:
Type of value has a mismatch with column typeCouldn't store <2019-04-18 12:32:11 PM> in dCurrantDate Column. Expected type is DateTime.
Try this
public void MakeDataTable(){
DataTable myTable;
DataRow myNewRow;
// Create a new DataTable.
myTable = new DataTable("My Table");
//ADDING DATETIME COLUMN
DataColumn colDateTime = new DataColumn("DateTimeCol");
colDateTime.DataType = System.Type.GetType("System.DateTime");
myTable.Columns.Add(colDateTime);
//ADDING ROW TO DATA-Table
myNewRow = myTable.NewRow();
myNewRow["DateTimeCol"] = System.DateTime.Now;
myTable.Rows.Add(myNewRow);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With