First, let's talk about the general idea of my implementation: 1. Read excel Data and assign values to datatable. Then, the detailed description is displayed on the page: Some columns are saved to the database in the datetime format, dataColumndtColumnnewDataColumn (); dtColumn. dataTypeSystem. ty
First, let's talk about the general idea of my implementation: 1. Read excel Data and assign values to datatable. Then, the detailed description is displayed on the page: Some columns are saved to the database in the datetime format, dataColumn dtColumn = new DataColumn (); dtColumn. dataType = System. ty
First, let's talk about the general idea of my implementation:
<1>Read excel Data, assign values to able, and then display on the page
Details: Some columns are saved in the datetime format when stored in the database, and I also perform the following processing when assigning values to the able.
DataColumn dtColumn = new DataColumn ();
DtColumn. DataType = System. Type. GetType ("System. DateTime ");
<2>Save the datatable to sqlserver
2.1 using a stored procedure with parameters, I have implemented this method (a column inserted in one row can also be inserted in the datetime column, and can be viewed in sqlserver)
2.2 When SqlBulkCopy is used (to improve efficiency as much as possible), the following error occurs:
Implementation Details:
string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; using(SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn)) { bulkCopy.DestinationTableName = "dbo.*****"; try { bulkCopy.WriteToServer(dt); } catch (Exception ex) { Response.Write(ex.Message); } } }
The following error is reported:
The given value of type String from the data source cannot be converted to type datetime of the specified target column. RunTime
Now we are stuck on sqlbulkcopy. Please advise. Thank you very much.