Friday, August 2, 2013

bulk copy from excel to sql server in asp.net

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb

Dim strConString As String = String.Empty
Dim Excelds As DataSet
Excelds = New DataSet()
            strConString = System.Configuration.ConfigurationManager.ConnectionStrings("Con").ConnectionString
            Dim bcp As SqlBulkCopy = New SqlBulkCopy(strConString)
            bcp.DestinationTableName = "dbo.TblBulk"
            'mapping required if source and destination column names are different
            bcp.ColumnMappings.Add("NO", "SeqNo")
            bcp.ColumnMappings.Add("UserId", "UserId")
            bcp.ColumnMappings.Add("Name", "Name")
            bcp.ColumnMappings.Add("DateCreated", "DateCreated")
            bcp.WriteToServer(Excelds.Tables(0))

No comments:

Post a Comment