I have a list(of String) variable that has 150 items in it. I basically just want to add those values to a column in my table and was wondering how to do it?
Here's the relevant code. Obviously this doesn't work and from the error message I got regarding parameter already existing (on the 2nd loop no doubt) I can see why. I've just included it to demonstrate what I want. Everything is connecting okay etc... so it's just the best way to add the range. I saw the Parameters.AddRange but can't find a decent example of what it's about so don't know if that's relevant.
vb Code:
Dim cmd As String = "INSERT INTO Pathology (PathologyValue) VALUES (@Path)" Dim insrt As New SqlCommand(cmd, conn) Try conn.Open() For i As Integer = 0 To myList.Count - 1 insrt.Parameters.AddWithValue("@path", myList(i)) insrt.ExecuteNonQuery() Next conn.Close() Catch ex As SqlException MessageBox.Show(ex.Message) Catch ex As Exception MessageBox.Show(ex.Message) End Try




Reply With Quote