I have a list with values in it. I want to insert these values in a SQL table using a single INSERT statement.
Example: Say, there is a list with names (the size of the list is not constant). There is a STUDENTS table with NAME column. I want to insert in the STUDENTS table the names from the list using a single INSERT statement.
Right now I loop through the list and insert the value in the table. That means, the number of insert statements is equal to the length of the list.
List<String> Name;
foreach (String s in Name)
{
INSERT INTO STUDENTS (NAME) VALUES (s)
}
Is there a way I can accomplish this in a single SQL INSERT statement? Any help is much appreciated.