Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Inserts using loop

Status
Not open for further replies.

salmaan

Programmer
Nov 26, 2002
3
CY
I am getting (multiple)values from a list box (like 17,24,33,40 etc) which are unique emp ids. These values can be dynamic ie they can be more than two.These unique ids have common fields like dept., sal. etc whose values are common to all the empids.
I need to seperate these values from the string and insert them as single rows, but the dept and sal columns are common.
For ex. from the list box 2 employees(1,2) are selected who have the common deptid(say 10) and common salary(say 5000).
1,2 have to be seperated and inserted in the database along with the deptid and sal. ie 2 rows have to be inserted in the database.
I need the code for this.
 
Just split the empid and create two sql commands

Dim empid, i
empid = Split(Request.Form("empid"), ", ")

for i = 0 to UBound(empid)
sql = "INSERT INTO myTABLE (empid, dept, sal) VALUES("
sql = sql & "'" & empid(i) & "', '" & Request.Form(dept)
sql = sql & "', '" & Request.Form("sal") & "'"
conn.Execute sql, , 1
next

where conn is the connection to your DB. This will insert two rows if you have selected two employees. Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top