Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

SqlBulkCopy.WriteToServer not able to convert empty values to null in destination column

$
0
0
[u][b]Background:[/b][/u]I am trying to insert csv data into sql table using Powershell script(Import-CSVtoSQL.ps1) given on following web page:https://gallery.technet.microsoft.com/scriptcenter/Import-Large-CSVs-into-SQL-216223d9[u][b]Issue:[/b][/u]This script is failing when I try to import null values (The null value is represented as blank in CSV file) from CSV file to datetime type column in a sql table. it's throwing following error:[b][u]Error Message:[/u][/b] System.InvalidOperationException: The given value of type String from the data source cannot be converted to type datetime of the specified target column. ---> System.FormatException: Failed to convert parameter value from a String to a DateTime. ---> System.FormatException: String was not recognized as a valid DateTime. at System.DateTime.Parse(String s, IFormatProvider provider) at System.Convert.ToDateTime(String value, IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType, Boolean& coercedToDataFeed, Boolean& typeChanged, Boolean allowStreaming) --- End of inner exception stack trace --- at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType, Boolean& coercedToDataFeed, Boolean& typeChanged, Boolean allowStreaming) at System.Data.SqlClient.SqlBulkCopy.ConvertValue(Object value, _SqlMetaData metadata, Boolean isNull, Boolean& isSqlType, Boolean& coercedToDataFeed) --- End of inner exception stack trace ---

Viewing all articles
Browse latest Browse all 467

Trending Articles