Really need help ASAP with ASP, looping, inserting from database SP

C

clinttoris

Hello,

If someone could help me it would be appreciated as I am not having
much luck.
I'm struggling with my asp code and have some questions relating to asp
and oracle database.

First question. I have a web survey that I am working on and have
successfully dynamically taken the info from a database, displayed it
on the screen and then taken the users answers and inserted them into a
database table. Let me explain the problem now that you have the
background by showing my code.
Code:
<table width="60%" cellspacing="0" cellpadding="5">
<%
Do while not objRS.eof
response.write (objRS("Question_Id")& ". ")&(objRS("Descr")&
"<BR>") & "<BR>"
Do while not objTxt.eof
%>
<% If (objTxt("Type")) = "Radio" then %>
<input type="checkbox" name="questions"
value="<%=objTxt("sub_text")%>"> <%=(objTxt("Text")&"<BR>")%>
<input type="hidden" name="HiddenSurveyID"
value="<%=objRS("Survey_ID")%>">
<input type="hidden" name="HiddenQuestionID"
value="<%=objRS("Question_id")%>">
<input type="hidden" name="HiddenText"
value="<%=objTxt("text")%>">
<%ELSE%>
<br><%=(objTxt("Text"))%>&nbsp;&nbsp;<input type="text" size
="75" name="textBoxAnswer"
value=""> <BR>

<%End IF%>
<%
objTxt.movenext()
Loop
objRS.movenext()%>
<BR>
<%
Loop
%>
</table>

This is the main code that loops through each question from the
database and then displays the question and associated choices
underneath.
ie.How are you today
good(checkbox field)
Not bad(checkbox field)
excellent(checkbox field)

Other(Text box field)

The answers(ie.good, not bad etc) have values stored with a,b,c,d in
the database. When the user chooses good for instance I want the value
A to be written to the database and in another column in the database
the value GOOD. Instead it is writing A and then "good,not
bad,excellent,other". It is looping but have no idea how to just take
the value that they selected rather then inserting all the values. If
the whole structure of the loop needs to be changed please change it to
whatever you experts think is needed.

Secondly, how do I take the value of the text input field if other is
chosen for the associated question and then add D(or whatever value it
is) and the users text value(i.e what ever they fill in the text box).
So in the above example, if the user chooses other and writes in the
text box(horrible day, got into an accident), I want to insert into the
database d and "horrible day, got into an accident". Here is the code
that passes those values
Code:
<%
oConn.Open

Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = oConn
oCmd.CommandType = 4
oCmd.CommandText = "surveyanswerinsert.surveyanswerinsert"

oCmd.Parameters.Append oCmd.CreateParameter("SurveyID", adVarChar,
adParamInput, 400, Request.Form("HiddenSurveyID"))
oCmd.Parameters.Append oCmd.CreateParameter("AnswerID", adVarChar,
adParamInput, 900, Request.Form("questions"))
oCmd.Parameters.Append oCmd.CreateParameter("Text", adVarChar,
adParamInput, 900, Request.Form("HiddenText"))
oCmd.Execute
%>

Lastly, as you can see with the above code you might be wondering why I
used adVarchar for SurveyID and AnswerID. Well I don't want to but if I
make the surveyID adNumeric and change the survey id field in the
database to Number and run this code on the web I get
Code:

Error Type:
ADODB.Command (0x800A0D5D)
Application uses a value of the wrong type for the current operation.


It only works with adVarchar. Could someone tell me what I am doing
wrong. It's oracle 9 and classic asp.

Thanks experts and sorry for all the questions.
 
J

Jeff Cochran

The answers(ie.good, not bad etc) have values stored with a,b,c,d in
the database. When the user chooses good for instance I want the value
A to be written to the database and in another column in the database
the value GOOD. Instead it is writing A and then "good,not
bad,excellent,other". It is looping but have no idea how to just take
the value that they selected rather then inserting all the values. If
the whole structure of the loop needs to be changed please change it to
whatever you experts think is needed.

Stop using checkboxes, use a radio button. Unless you really mant to
select more than one. And the selected item's value is the VALUE
assigned in the radio button that gets checked. if you want
additional info in a new field, you have to do an IF/THEN on the
value, something like:

IF VALUE="A" THEN DATA="Chevy"

Insert that into the database in your SQL INSERT statement.
Secondly, how do I take the value of the text input field if other is
chosen for the associated question and then add D(or whatever value it
is) and the users text value(i.e what ever they fill in the text box).
So in the above example, if the user chooses other and writes in the
text box(horrible day, got into an accident), I want to insert into the
database d and "horrible day, got into an accident". Here is the code
that passes those values

Again, learn to use forms. The same process is used, but if the
VALUE="D" THEN DATA = TextBoxValue.
Lastly, as you can see with the above code you might be wondering why I
used adVarchar for SurveyID and AnswerID. Well I don't want to but if I
make the surveyID adNumeric and change the survey id field in the
database to Number and run this code on the web I get
Code:
Error Type:
ADODB.Command (0x800A0D5D)
Application uses a value of the wrong type for the current operation.

That's a "Well, duh.." kind of statement. You can't use a letter in a
numeric field. Nothing wrong with VARCHAR except that if the field
length is always 1 (A, B, C, etc...) then it's not really VAR is it?
Just a CHAR with a length of 1.

Note that you'l need to use whatever Oracle has, I've used SQL Server
for so long I almost forgot how to spell "Oracle".

Jeff
 
C

clinttoris

Jeff said:
Stop using checkboxes, use a radio button. Unless you really mant to
select more than one. And the selected item's value is the VALUE
assigned in the radio button that gets checked. if you want
additional info in a new field, you have to do an IF/THEN on the
value, something like:

IF VALUE="A" THEN DATA="Chevy"

Insert that into the database in your SQL INSERT statement.


Again, learn to use forms. The same process is used, but if the
VALUE="D" THEN DATA = TextBoxValue.



That's a "Well, duh.." kind of statement. You can't use a letter in a
numeric field. Nothing wrong with VARCHAR except that if the field
length is always 1 (A, B, C, etc...) then it's not really VAR is it?
Just a CHAR with a length of 1.

Note that you'l need to use whatever Oracle has, I've used SQL Server
for so long I almost forgot how to spell "Oracle".

Jeff



Jeff thanks for getting back to me.

O.k I wish I could use any of the info you provided but I cannot as it
doesn't apply.
As for using the radio buttons. This will not work as I need to select
multiple values. My questions usually end with select all that apply?
So using radio buttons will not work and that is why I am using check
boxes. Any ideas how to construct my loop or just take the values the
user selects from my checkboxes as posted in my original question?

Secondly I know how to use forms but if my loop is not constructed
properly my passing of data will be affected so therefore I will not be
able to capture the proper text. So your answer will not be sufficient
either.

Thirdly, the surveyID and answerID is not getting passed a letter it
is getting passed a number. So your statement Well, duh.." kind of
statement is incorrect as you are mistaken as to what value was being
passed. I'm assuming because my loop and hidden fields are not working
correctly the value 1,1,1,1 is being passed as a string so the
AdNumeric will not function. But I need someone to first fix my loop
using the required checkboxes needed. Thanks for your replies Jeff and
wish I could use anything you said but unfortunately I cannot.

Also, I wish I could use SQL server which I have over the past 7 yrs
unfortunately my new company is using Oracle. Ya that Sucks:(

Any other ideas?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top