By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

Comma delimited array into DB problems

P: n/a

From: "Arne de Booij" <a_********@hotmail.com>
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!
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
How do you the values into a comma delimited string?

"Arne" <a_********@hotmail.com> wrote in message
news:eh**************@TK2MSFTNGP11.phx.gbl...

From: "Arne de Booij" <a_********@hotmail.com>
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!

Jul 19 '05 #2

P: n/a
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" <a_********@hotmail.com> wrote in message
news:eh**************@TK2MSFTNGP11.phx.gbl...

From: "Arne de Booij" <a_********@hotmail.com>
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!

Jul 19 '05 #3

P: n/a

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!
Jul 19 '05 #4

P: n/a
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" <aa***@TRASHaspfaq.com> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
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" <a_********@hotmail.com> wrote in message
news:eh**************@TK2MSFTNGP11.phx.gbl...

From: "Arne de Booij" <a_********@hotmail.com>
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!


Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.