Not giving the parameters datatypes and sizes can slow things down. Check http://www.dbdelta.com/addwithvalue-is-evil/
and
https://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using-addwithvalue-already/
and another one
https://dba.stackexchange.com/questions/195937/addwithvalue-performance-and-plan-cache-implications
I passed in a List(Of Employee) which assumes a Class called Employee with Properties call FirstName and LastName but any enumerable containing the values you want to enter should work.
Add the parameters once outside the loop. Open the connection once, just before the loop and change the values of the parameters inside the loop.
The Using blocks will close and dispose your database objects.
Private Sub AddEmplyees(empList As List(Of Employee))
Using connection As SqlConnection = New SqlConnection("CONNECTION STRING")
Using command As New SqlCommand("Insert Into Employess (FirstName, LastName) Values (@FirstName, @LastName);", connection)
command.Parameters.Add("@FirstName", SqlDbType.VarChar, 50)
command.Parameters.Add("@LastName", SqlDbType.VarChar, 100)
connection.Open()
For Each e In empList
command.Parameters("@FirstName").Value = e.FirstName
command.Parameters("@LastName").Value = e.LastName
command.ExecuteNonQuery()
Next
End Using
End Using
End Sub