Home > Database > Mysql Tutorial > body text

excel数据存入sqlserver过程中,遇到Datetime的格式问题。

WBOY
Release: 2016-06-07 15:40:04
Original
1450 people have browsed it

先讲一下我实现的大致思路: 1 读取excel数据,赋值到datatable中,然后在页面上显示 细节描述:有一些列是存到数据库时要是datetime格式的,我在赋值到datatable时也是做 如下处理的 DataColumn dtColumn = new DataColumn(); dtColumn.DataType =System.Ty

先讲一下我实现的大致思路:

读取excel数据,赋值到datatable中,然后在页面上显示

       细节描述:有一些列是存到数据库时要是datetime格式的,我在赋值到datatable时也是做                      如下处理的

                   DataColumn dtColumn = new DataColumn();               

                   dtColumn.DataType =System.Type.GetType("System.DateTime");

将datatable存到sqlserver中

      2.1使用带参数的存储过程,这种方法我已经实现(一行一行插入的,遇到datetime那一列            也是一样可以插入的,并可以在sqlserver中查看)

      2.2在使用SqlBulkCopy时(想尽可能提高效率),遇到如下错误

           实现细节描述:

            

<span>string</span> connStr = ConfigurationManager.ConnectionStrings[<span>"</span><span>connStr</span><span>"</span><span>].ConnectionString;
            </span><span>using</span>(SqlConnection conn = <span>new</span><span> SqlConnection(connStr))
            {
                conn.Open();
                </span><span>using</span> (SqlBulkCopy bulkCopy = <span>new</span><span> SqlBulkCopy(conn))
                {
                    bulkCopy.DestinationTableName </span>= <span>"</span><span>dbo.*****</span><span>"</span><span>;
                    </span><span>try</span><span>
                    {
                        bulkCopy.WriteToServer(dt);
                    }
                    </span><span>catch</span><span> (Exception ex)
                    {

                        Response.Write(ex.Message);
                    }
                    
                }
            }</span>
Copy after login

 

遇到如下错误:

         The given value of type String from the data source cannot be converted to                type datetime of the specified target column.RunTime

 

现在就是卡在使用sqlbulkcopy上,求大家支招。小弟不胜感激

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!