Dynamic checkboxes & INSERT into DB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Collins

    Dynamic checkboxes & INSERT into DB

    Can anyone point me to some good examples on the web of
    using values from dynamically created checkboxes on forms
    in ASP, particularly relating to INSERTING those values
    into a SQL or Access database?

    Basically, I have a form on which I have a series of
    statements, with 3 checkboxes for each statement - YES,
    NO, MAYBE. This series of statements is being dynamically
    populated from a query of a table in Access,
    called "tblQuestio ns". In the form, I created a hidden
    field named "QuestionID " to return the QuestionID. The
    checkboxes are named YESz, NOz, and MAYBEz, and set to
    return a value of "ON" if checked.

    I created another table called "tblQuestionAns wers" into
    which I want to insert records, in which I have 6 fields -
    1) QAID - an autonumber primary index field, 2)
    QuestionID, 3) CompanyID, 4) YesZ, 5) NOz, 6) MAYBEz - the
    z is used to reduce the risk of complications from any
    reserved fields.

    In my update ASP code page, I defined the variables from
    the form, and set 3 IF/THEN statements to resolve any NULL
    issues with the checkboxes:

    IF(IsNull(Reque st.Form("YESz") )) Then
    YESz = 0
    Else
    YESz = 1
    End IF

    Etc., for all 3 checkboxes.

    Then I tried to create an array and a database connection
    to INSERT:

    Dim arrayQuestionID
    Dim arrayCompanyID
    Dim arrayYESz
    Dim arrayNOz
    Dim arrayMAYBEz
    Dim i

    arrayQuestionID = split(QuestionI D,",")
    arrayCompanyID - split(CompanyID ,",")
    arrayYESz = split(YESz,",")
    arrayNOz = split(NOz,",")
    arrayMAYBEz = split(MAYBEz,", ")

    for i = 0 to ubound(arrayQue stionID)
    intCompanyID = arrayCompanyID( i)
    intYESz = arrayYESz(i)
    intNOz = arrayNOz(i)
    intMAYBEz = arrayMAYBEz(i)

    set myConn=Server.C reateObject("ad odb.connection" )
    myConn.Open "DB"
    myConn.Execute "INSERT INTO tblQuestionAnsw ers
    (QuestionID,Com panyID,YESz,NOz ,MAYBEz) VALUES (" &
    [color=blue]
    >arrayQuestionI D(i) & "," & intCompanyID & "," & intYESz[/color]
    & "," & intNOz & "," & intMAYBEz & ")"
    intCompanyID(i)
    intSvcOffering( i)
    intSvcExemplary (i)
    intSvcIntereste d(i)
    Next
    myConn.Close
    set myConn = Nothing

    Basically, I'm now getting a type mismatch error during
    the INSERT process. At other times, trying other things, I
    have gotten a "Subscript out of range" error. And I'm not
    really sure that the thing is iterating over the array,or
    if I have the array properly written.

    Obviously, I have failed to do something properly! LOL
    I've been stuck on this issue for 3 days. Any help that
    anyone can give me will be GREATLY APPRECIATED! LOL

    "I am an ASP newbie, therefore an ASP ignoramus!" LOL

    ---------------
    Frank Collins
Working...