I am assuming that you are using MySQL, because in your original question you didnt mentioned MySQL. But I see tags added as MySQL and VB.NET
if there are only 100 rows you want to insert in a loop, you will not see much of a difference when you optimize. but if you want to insert lot of rows (more than 10,000) in bulk, the best way is to create a data adapter then fill a dataset, set the primary key on dataset same as actual table, then add rows into the dataset (in memory), and then fire datadapter.update() and pass the dataset. this way the data adapter will insert the records most effeciently (same when you want to update in bulk).
but in your case you should not worry too much about the performance as it's only 100 rows (you will not see that milisecond improvement). but you should avoid any sql injection attacks by passing the values with parameter. for security never use inline sql.
(like
string strQuery = "Select * From Users Where Password = '" + strPassword + "' And UserName = '" + strUserName + "'
").
always use parameter, (or call stored procedure)
Dim da As MySqlDataAdapter = New MySqlDataAdapter()
Dim cmd As MySqlCommand
Dim parm As MySqlParameter
cmd = New MySqlCommand("SELECT * FROM mytable WHERE id=?id AND name=?name", conn)
cmd.Parameters.Add("?id", MySqlDbType.VarChar, 15)
cmd.Parameters.Add("?name", MySqlDbType.VarChar, 15)
da.SelectCommand = cmd
cmd = New MySqlCommand("INSERT INTO mytable (id,name) VALUES (?id, ?name)", conn)
cmd.Parameters.Add( "?id", MySqlDbType.VarChar, 15, "id" )
cmd.Parameters.Add( "?name", MySqlDbType.VarChar, 15, "name" )
da.InsertCommand = cmd
you can find more information about data adapter
on this link[
^].