I would create a sub-procedure (or whatever its called in VB.Net) and put this code
cmd.Parameters.AddWithValue("@RID", TextBox2.Text)
cmd.Parameters.AddWithValue("@ROOMID", ComboBox1.SelectedValue)
cmd.Parameters.AddWithValue("@STATUS", "No")
cmd.ExecuteNonQuery()
in it, with the exception that into the sub-procedure, you have to pass your parameters, so you have something roughly like
Private Sub multipleRoomAdd(loopValue As Integer, cmd as MySqlCommand, tb2_Value As String, cb1_Value As String, Status as String)
cmd.Parameters.AddWithValue("@RID", tb2_Value)
cmd.Parameters.AddWithValue("@ROOMID", cb1_Value)
cmd.Parameters.AddWithValue("@STATUS", Status)
cmd.ExecuteNonQuery()
End Sub
so that you can then do
cmd = ... // As Per your code
For addLoopIndex As Integer = 1 to i
multipleRoomAdd(addLoopIndex, cmd, TextBox2.Text, ComboBox1.SelectedValue, "No")
End For
but, you're not out of the woods yet ! you need to think about :-
1. using LoopValue which will go from 1 to 10 (for example) to alter/form the values for @RID/tb2_Value and/or @ROOMID/cb1_Value - if you dont create new values, possibly based on the loop #, you'll end up with rows all the same, I doubt thats what you want (btw why are these two similar ?) - I'd likely use a Sub Procedure here to mutate/get the values required on each iteration
2. possibly reset the cmd parameters
so you possibly end up with
Private Sub multipleRoomAdd(loopValue As Integer, cmd As MySqlCommand, tb2_Value As String, cb1_Value As String, Status As String)
// Use loopValue 1..n and tb2_Value from TextBox2 to get new RID value
newRIDValue = getNewRID(loopValue, tb2_Value)
cmd.Parameters.AddWithValue("@RID", newRIDValue)
// Use loopValue 1..n and cb1_Value from ComboBox1 to get new ROOMID value
newROOMIDValue = getNewROOMID(loopValue, cb1_Value)
cmd.Parameters.AddWithValue("@ROOMID", newROOMIDValue)
cmd.Parameters.AddWithValue("@STATUS", Status)
cmd.ExecuteNonQuery()
// ? Reset cmd Parameter List
cmd.Parameters.Reset() ??
End Sub
//TODO
// 1 Define a sub Procedure for getNewRID that given loopValue (eg 1..10) and The TextBox2.Text Value, returns a new (unique ?) RID
// 2 Define a sub Procedure for getNewROOMID that given a loopValue (eg 1..10) and the ComboBox1.SelectedText Value, returns a new ROOMID
I dont write VB - so just use this as an idea of what you could do, dont use it verbatim, I doubt any of its legal VB anyway - good luck