Comma delimited array into DB problems

Discussion in 'ASP General' started by Arne, Feb 9, 2004.

  1. Arne

    Arne Guest

    From: "Arne de Booij" <>
    Subject: Comma delimited array into DB problems
    Date: 9. februar 2004 10:39

    Hi,

    I have an asp page that takes input from a form on the previous page,
    puts that into an array and inserts the array into SQL server.

    Now here is the problem:

    The form on the page where the user can enter information contains a
    dynamic amount of text boxes with the same name. So when the user
    submits their entry, I get a comma delimited string.

    e.g. First entry, Second entry, Third entry

    The problem comes when a user enters a comma in the text field

    e.g. First entry, with a comma, Second entry, Third Entry.

    My code will put "with a comma" into a different row in the DB than
    "First entry" because of the comma in the string.

    Any ideas on how to solve this?


    CODE (somewhat simplified)

    Detailsvar = request("details")
    details = Replace(Detailsvar, "'", "''") 'array

    Dim deArray
    deArray = Split(details, ", ")

    FOR i = Lbound(deArray) TO Ubound(deArray)
    DB.Execute("sp_insert_ratings '" & deArray(i) & "'")
    NEXT

    Arne



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Arne, Feb 9, 2004
    #1
    1. Advertising

  2. Arne

    Alex Goodey Guest

    How do you the values into a comma delimited string?

    "Arne" <> wrote in message
    news:ehC$...
    >
    > From: "Arne de Booij" <>
    > Subject: Comma delimited array into DB problems
    > Date: 9. februar 2004 10:39
    >
    > Hi,
    >
    > I have an asp page that takes input from a form on the previous page,
    > puts that into an array and inserts the array into SQL server.
    >
    > Now here is the problem:
    >
    > The form on the page where the user can enter information contains a
    > dynamic amount of text boxes with the same name. So when the user
    > submits their entry, I get a comma delimited string.
    >
    > e.g. First entry, Second entry, Third entry
    >
    > The problem comes when a user enters a comma in the text field
    >
    > e.g. First entry, with a comma, Second entry, Third Entry.
    >
    > My code will put "with a comma" into a different row in the DB than
    > "First entry" because of the comma in the string.
    >
    > Any ideas on how to solve this?
    >
    >
    > CODE (somewhat simplified)
    >
    > Detailsvar = request("details")
    > details = Replace(Detailsvar, "'", "''") 'array
    >
    > Dim deArray
    > deArray = Split(details, ", ")
    >
    > FOR i = Lbound(deArray) TO Ubound(deArray)
    > DB.Execute("sp_insert_ratings '" & deArray(i) & "'")
    > NEXT
    >
    > Arne
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    >
    >
     
    Alex Goodey, Feb 9, 2004
    #2
    1. Advertising

  3. You could treat the form element as a collection, rather than as a comma
    separated string.

    <form method=post>
    <input type=text name=x value="a, b">
    <input type=text name=x value="c">
    <input type=text name=x value="d">
    <input type=submit>
    </form>

    <%
    for i = 1 to request.form("x").count
    response.write request.form("x")(i) & "<br>"
    next
    %>

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/




    "Arne" <> wrote in message
    news:ehC$...
    >
    > From: "Arne de Booij" <>
    > Subject: Comma delimited array into DB problems
    > Date: 9. februar 2004 10:39
    >
    > Hi,
    >
    > I have an asp page that takes input from a form on the previous page,
    > puts that into an array and inserts the array into SQL server.
    >
    > Now here is the problem:
    >
    > The form on the page where the user can enter information contains a
    > dynamic amount of text boxes with the same name. So when the user
    > submits their entry, I get a comma delimited string.
    >
    > e.g. First entry, Second entry, Third entry
    >
    > The problem comes when a user enters a comma in the text field
    >
    > e.g. First entry, with a comma, Second entry, Third Entry.
    >
    > My code will put "with a comma" into a different row in the DB than
    > "First entry" because of the comma in the string.
    >
    > Any ideas on how to solve this?
    >
    >
    > CODE (somewhat simplified)
    >
    > Detailsvar = request("details")
    > details = Replace(Detailsvar, "'", "''") 'array
    >
    > Dim deArray
    > deArray = Split(details, ", ")
    >
    > FOR i = Lbound(deArray) TO Ubound(deArray)
    > DB.Execute("sp_insert_ratings '" & deArray(i) & "'")
    > NEXT
    >
    > Arne
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    >
    >
     
    Aaron Bertrand - MVP, Feb 9, 2004
    #3
  4. The form on the page where the user can enter information contains a
    dynamic amount of text boxes with the same name.

    e.g.

    <FORM ...>
    Textbox1: First comment
    <BR>
    Textbox1: Second comment
    <BR>
    Textbox1: Third comment
    <BR>
    </FORM>

    When you submit this and request it on the next page
    (request("Textbox1")) you get the string: First comment, Second comment,
    Third comment.

    So it is basically automatic.

    >How do you the values into a comma delimited string?


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Arne de Booij, Feb 9, 2004
    #4
  5. Arne

    Arne Guest

    Hi Aaron,

    your comment sent me in the right direction. I was able to make minor
    adjustments to the entire code to get it to work.

    thanks!
    ___________

    "Aaron Bertrand - MVP" <> wrote in message
    news:...
    > You could treat the form element as a collection, rather than as a comma
    > separated string.
    >
    > <form method=post>
    > <input type=text name=x value="a, b">
    > <input type=text name=x value="c">
    > <input type=text name=x value="d">
    > <input type=submit>
    > </form>
    >
    > <%
    > for i = 1 to request.form("x").count
    > response.write request.form("x")(i) & "<br>"
    > next
    > %>
    >
    > --
    > Aaron Bertrand
    > SQL Server MVP
    > http://www.aspfaq.com/
    >
    >
    >
    >
    > "Arne" <> wrote in message
    > news:ehC$...
    > >
    > > From: "Arne de Booij" <>
    > > Subject: Comma delimited array into DB problems
    > > Date: 9. februar 2004 10:39
    > >
    > > Hi,
    > >
    > > I have an asp page that takes input from a form on the previous page,
    > > puts that into an array and inserts the array into SQL server.
    > >
    > > Now here is the problem:
    > >
    > > The form on the page where the user can enter information contains a
    > > dynamic amount of text boxes with the same name. So when the user
    > > submits their entry, I get a comma delimited string.
    > >
    > > e.g. First entry, Second entry, Third entry
    > >
    > > The problem comes when a user enters a comma in the text field
    > >
    > > e.g. First entry, with a comma, Second entry, Third Entry.
    > >
    > > My code will put "with a comma" into a different row in the DB than
    > > "First entry" because of the comma in the string.
    > >
    > > Any ideas on how to solve this?
    > >
    > >
    > > CODE (somewhat simplified)
    > >
    > > Detailsvar = request("details")
    > > details = Replace(Detailsvar, "'", "''") 'array
    > >
    > > Dim deArray
    > > deArray = Split(details, ", ")
    > >
    > > FOR i = Lbound(deArray) TO Ubound(deArray)
    > > DB.Execute("sp_insert_ratings '" & deArray(i) & "'")
    > > NEXT
    > >
    > > Arne
    > >
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***
    > > Don't just participate in USENET...get rewarded for it!
    > >
    > >

    >
    >
     
    Arne, Feb 9, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yama

    Comma Delimited

    Yama, Dec 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    407
    Ken Cox [Microsoft MVP]
    Dec 16, 2003
  2. Luis Esteban Valencia

    Read Comma Delimited File

    Luis Esteban Valencia, Jul 27, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,820
    Paul Clement
    Jul 27, 2005
  3. Edward A Thompson

    JavaMail MimeMessage - comma delimited?

    Edward A Thompson, Oct 8, 2003, in forum: Java
    Replies:
    9
    Views:
    5,673
    GaryM
    Oct 10, 2003
  4. ouioui
    Replies:
    1
    Views:
    1,650
    Mukul Gandhi
    Sep 23, 2004
  5. RyanL
    Replies:
    6
    Views:
    702
    Paul McGuire
    Aug 28, 2007
Loading...

Share This Page