beccatigger Posted August 23, 2006 Share Posted August 23, 2006 I'm having trouble trying to insert checkbox values into an access database. Basically, I've got a form with checkboxes in and checkbox values. It takes the checked checkbox values, then split them into an array. Now I want to put the array values into a table (on seperate rows, so multiple inserts at once). The table structure is CustomerNumber & CustomerType which are both numbers. The customernumber is the same for each checkbox value inserted during the form submission.Currently I can get this code to work to write out each checkbox value like this:<% CT= Request.Form("ctcheckbox")myArray=Split(CT,",")For i=LBound(myArray) to UBound(myArray)Response.Write myArray(i)Next%>But I need to include it in this code to insert it into the database, but I don't know how to reference the array:<%if(Request.Form("Comnum") <> "") then Command1__CN = Request.Form("Comnum")%><%set Command1 = Server.CreateObject("ADODB.Command")Command1.ActiveConnection = MM_conn2_STRINGCommand1.CommandText = "INSERT INTO CustomerTypes (CustomerNumber, CustomerType) VALUES (" + Replace(Command1__CN, "'", "''") + ",'myArray') "Command1.CommandType = 1Command1.CommandTimeout = 0Command1.Prepared = trueCommand1.Execute()%> Link to comment Share on other sites More sharing options...
Chozo4 Posted September 1, 2006 Share Posted September 1, 2006 (edited) edited out - jumped the gun here and misread a few sections. My apologies as I additionally know nothing about ASP here.Afterthought: Have you tried referencing your array directly such as myarray(0) myarray(1) myarray(2) and so forth? Additonally, have you tried using an array conversion function to convert it into a string? Since the myarray in red seems to be sent as if you're trying to send the whole array at once.There is a good tutorial on ASP arrays onhttp://www.codefixer.com/tutorials/arrays.asphttp://www.codefixer.com/tutorials/array_functions.asp Edited September 1, 2006 by Chozo4 Link to comment Share on other sites More sharing options...
IcemanND Posted September 1, 2006 Share Posted September 1, 2006 Two ways you could do it. Depends upon how dynamic you want this to be for future changes.<%myArray=Split(CT,",")For i=LBound(myArray) to UBound(myArray) AddValues = AddValue + ",'" + Response.Write myArray(i) + "'"Nextset Command1 = Server.CreateObject("ADODB.Command")Command1.ActiveConnection = MM_conn2_STRINGCommand1.CommandText = "INSERT INTO CustomerTypes (CustomerNumber, CustomerType) VALUES (" + Replace(Command1__CN, "'", "''")" + AddValues +") "Command1.CommandType = 1Command1.CommandTimeout = 0Command1.Prepared = trueCommand1.Execute()%>or<%myArray=Split(CT,",")set Command1 = Server.CreateObject("ADODB.Command")Command1.ActiveConnection = MM_conn2_STRINGCommand1.CommandText = "INSERT INTO CustomerTypes (CustomerNumber, CustomerType) VALUES (" + Replace(Command1__CN, "'", "''")" + ",'" +myArray(0) + "','" + myArray(1) +"') "Command1.CommandType = 1Command1.CommandTimeout = 0Command1.Prepared = trueCommand1.Execute()%>The first will let you add as many checkboxes as you like without have to keep adding myArray(x) to the end of the update query.Note: I may have missed a quote here or there. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now