Torna al Thread

Dim dt As New DataTable() Dim line As String = Nothing Dim i As Integer = 0 Using sr As StreamReader = File.OpenText("c:\temp\table1.csv") line = sr.ReadLine() Do While line IsNot Nothing Dim data() As String = line.Split(","c) If data.Length > 0 Then If i = 0 Then For Each item In data dt.Columns.Add(New DataColumn()) Next item i += 1 End If Dim row As DataRow = dt.NewRow() row.ItemArray = data dt.Rows.Add(row) End If line = sr.ReadLine() Loop End Using Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConsoleApplication3.Properties.Settings.daasConnectionString").ConnectionString) cn.Open() Using copy As New SqlBulkCopy(cn) copy.ColumnMappings.Add(0, 0) copy.ColumnMappings.Add(1, 1) copy.ColumnMappings.Add(2, 2) copy.ColumnMappings.Add(3, 3) copy.ColumnMappings.Add(4, 4) copy.DestinationTableName = "Censis" copy.WriteToServer(dt) End Using End Using
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5