hi
how to import data from CSV, import data begin from row 2 because row 1 there is title
i have code like this
Dim csvPath As String = Server.MapPath("~/Files/") + Path.GetFileName(FileUpload1.PostedFile.FileName)
FileUpload1.SaveAs(csvPath)
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(0) {New DataColumn("kodecustomer", GetType(String))})
Dim csvData As String = File.ReadAllText(csvPath)
For Each row As String In csvData.Split(ControlChars.Lf)
If Not String.IsNullOrEmpty(row) Then
dt.Rows.Add()
Try
Dim i As Integer = 0
For Each cell As String In row.Split(","c)
dt.Rows(dt.Rows.Count - 1)(i) = cell
i += 1
Next
Catch ex As Exception
pesan("Data Tidak Boleh Pakai , Atau '' Atau "" ")
Exit Sub
End Try
End If
Next
'Dim consString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(ambilstringkoneksi)
Using sqlBulkCopy As New SqlBulkCopy(con)
'Set the database table name.
sqlBulkCopy.DestinationTableName = "[tblimportmining]"
con.Open()
Try
sqlBulkCopy.WriteToServer(dt)
pesan("Data sudah selesai Di Import.")
Catch ex As Exception
pesan("File CSV Salah. Atau Format File CSV Tidak Sesuai.")
End Try
con.Close()
End Using
End Using
thanks