I'm hoping I am doing this correctly but what I am currently doing is running through each row of a datatable and using an insert command on each row, inserting the records to a table in a MySQL database.
Below are the parameter statements and on the second one I am getting an error
"Conversion from type 'DBNull' to type 'Date' is not valid."
I checked the original data and of course it is null. So I started looking around to determine what to do to correct the issue. From what I can tell, I need to check if it is null but I am not sure if what I have done is correct. It looks like it still sends Null to my database which is ok, I would just like to check to make sure this code below is the best solution.
Is it possible for someone to have a look and validate if I am doing it correctly? It appears ok and my reports on the data seem to work ok. TIA, rasinc
Below are the parameter statements and on the second one I am getting an error
"Conversion from type 'DBNull' to type 'Date' is not valid."
VB.Net Code:
'adding to the parameter collection strSQLCmd.Parameters.Add("@CustomerSince", MySqlDbType.DateTime) 'while running through records in a datatable using an insert command to save to a MySQL table strSQLCmd.Parameters("@CustomerSince").Value = CDate(row("CustomerSince"))
I checked the original data and of course it is null. So I started looking around to determine what to do to correct the issue. From what I can tell, I need to check if it is null but I am not sure if what I have done is correct. It looks like it still sends Null to my database which is ok, I would just like to check to make sure this code below is the best solution.
VB.Net Code:
If Not IsDBNull(row("CustomerSince")) Then strSQLCmd.Parameters("@CustomerSince").Value = CDate(row("CustomerSince")) End If
Is it possible for someone to have a look and validate if I am doing it correctly? It appears ok and my reports on the data seem to work ok. TIA, rasinc