Loop through a list box | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Loop through a list box

I have 2 list boxes, one for language,s spoken at home
and the other is for mother tongue,s.
The 2 list boxes allow multiple choices. I want to handle
the inserting of this data through stored procedure.
I do not know other code to handle the multiple choices of
the list box except to loop through it by "For each item"
but a problem occurs here which is that I need to esablish
a command object at each loop and close at the end of this loop
and so on which I do not like at all. Does any body knows a way
beter than this to handel inserting such data through a stored proc
My code is:
I = 1
For Each Item in Request.Form("Sel_SLang")
set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = Conn
cmd.CommandText = "dbo.Insert_SLanguages"
cmd.CommandType = adCmdStoredProc
With cmd
.parameters.Append cmd.CreateParameter ("@StudentID", adVarWChar, adParamInput, 50)
.parameters.Append cmd.CreateParameter ("@SLang", adInteger, adParamInput,4)
.parameters.Append cmd.CreateParameter ("@MLang", adInteger, adParamInput,4) .Parameters("@StudentID") = StudentCode
.Parameters("@SLang") = CInt(Item)
.Parameters("@MLang") = CInt(XItem) .Execute Ingrecs, , adExecuteNoRecords End With
set cmd = Nothing
X = X + 1
Next
I =I + 1
Next
Rasha zaki
Web Developer
Cairo, Egypt
You could pass to the procedure a delimited string and parse it inside the procedure. Check Joe Chang’s way to parse a string at http://www.sql-server-performance.com/forum/topic.asp?TOPIC_ID=1092.
From your code I could not understand if you are inserting one or more students each time. if you clarify this we could come up with some code.

]]>