Thursday, May 9, 2013

Strange behavior in datatable


Hi, I have a datatable with a column of type datetime, there is a situation where someone assign a message in this column, something like "hello world", and it´s not throwing an exception. I know that should not be, I can´t find a why it happens.


I check the column of the table in the database and its type is smalldatetime, also check the store procedure that brings data, and makes no conversion, finally, it uses a datareader to get data


Any idea why not throw the exception?




Datatable lobjTable = lobjPrest.FindData();


if (lobjTable != null && lobjTable.Rows.Count > 0) {


lobjTable.Rows[0]["Date"] = "Hello world"; //This column had datetime format


}



I must complete my question, I know if I put a string into datetime DataColumn throws an exception. In my development environment happens all the time, but in my environment prduccion not


The error occurs in this line


lobjTable.Rows[0]["Date"] = "Hello world"; //This column had datetime format


And throws this exception


System.ArgumentException - The string is not recognized as valid DateTime. There is an unknown word at the beginning of the index can be stored 0.No <Hello world> deadline of dueDate column. Expected type is DateTime.


No comments:

Post a Comment