Click here to Skip to main content
15,070,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello to all. Got a huge problem here. Currently I am studying bulk insert (which really pissed mo off >_<) and on my research i stumbbled across this code
Private Sub InsertFilenames()
    Using conn As New System.Data.SqlClient.SqlConnection("YourConnString")
        'Build an insert string containing an INSERT statement for each item.
        Dim text As New System.Text.StringBuilder()
        For Each filename As String In System.IO.Directory.GetFiles("Path", "Filter")
            text.Append("INSERT INTO YourTableName (FileName) VALUES ('")
            text.Append(filename)
            'Construct file name if needed...
            text.Append("' ")
        Next
        Dim cmd As New System.Data.SqlClient.SqlCommand(text.ToString(), conn)
        Try
            cmd.Connection.Open()
            cmd.ExecuteNonQuery()
            'Handle error...
        Catch sqlExc As System.Data.SqlClient.SqlException
        Finally
            If cmd.Connection IsNot Nothing Then
                cmd.Connection.Close()
            End If
        End Try
    End Using
End Sub

My question is what is the meaning of this especially "path", "filter"
For Each filename As String In System.IO.Directory.GetFiles("Path", "Filter")<br />
Im kinda confused cause my task is getting all data from excel and then saved it to sqlserver without any basics regarding this matter.

thanks in advance and more power!
Posted

1 solution

GetFiles ==> Returns the names of files (including their paths) that match the specified search pattern in the specified directory.

and ForEach loop looks for the filename which was return from GetFiles
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900