Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating database with info from text boxes 1

Status
Not open for further replies.

allyeric

Programmer
Mar 14, 2000
104
CA
I am creating a table using the information pulled from a database.&nbsp;&nbsp;When I am creating the table, I am also creating a cell that has a text box in it - which the user will put information into.&nbsp;&nbsp;Below is the code I used to create the table.&nbsp;&nbsp;My question is:&nbsp;&nbsp;I need to save the information the user enters in the text boxes into the database.&nbsp;&nbsp;I just don't know how to access that info.&nbsp;&nbsp;I did try using a session variable to hold an array, but it didn't update the database.&nbsp;&nbsp;Any hints would be greatly appreciated.<br><br>Thanks<br><br><br>For lQuestionNumber = 0 To 11<br>&nbsp;&nbsp;&nbsp;&nbsp;If sQuestion(lQuestionNumber) &lt;&gt; &quot;XXX&quot; Then<br>%&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;table width=&quot;1006&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TR&gt;&lt;TD width=&quot;33&quot;&gt; &lt;/TD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TD width=&quot;31&quot;&gt;&lt;% = sQuestion(lQuestionNumber)%&gt; &lt;/TD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TD width=&quot;33&quot;&gt;&lt;/TD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>&lt;TD width=&quot;24&quot;&gt;&lt;input type = &quot;text&quot; name=&quot;Answer&quot; width=3 size=&quot;2&quot;&gt;</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TD width=&quot;241&quot;&gt;&lt;/TD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TD width=&quot;29&quot;&gt;&lt;% =Index %&gt;&lt;/TD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TD width=&quot;265&quot;&gt;&lt;% =sAnswers(lQuestionNumber)%&gt;&lt;/TD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TD width=&quot;29&quot;&gt;&lt;% =Index + 12 %&gt;&lt;/TD&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TD width=&quot;265&quot;&gt;&lt;% =sAnswers(lQuestionNumber + 12) %&gt;&lt;/TD&gt;<br>&lt;%<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Index = Index + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>Next<br><br>
 
What about using FORM tags and a submit button. It seems that your HTML is going to be produced within a loop. Once the loop completes, the user will be able to interact with 12 ANSWER textboxes. Provide a SUBMIT button to go to an ASP page and retrieve all the values there. Your ANSWER textbox should be named:<br><br>&lt;TD width=&quot;24&quot;&gt;&lt;input type = &quot;text&quot; name=&quot;Answer&quot; & i width=3 size=&quot;2&quot;&gt;<br><br>So the names would be ANSWER0, ANSWER1, ANSWER2, etc. Once the Answer textboxes have unique names you can retrieve their values on the ASP page and by using ADO do an INSERT query on your database. <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
 
oh, one more question ...&nbsp;&nbsp;the table I am inserting into already has some values - can I use the UPDATE statement to insert the other values from the form?&nbsp;&nbsp;I keep trying but its not updating my database.&nbsp;&nbsp;Here is the code I am using:<br><br> Set objConn = Server.CreateObject (&quot;ADODB.Connection&quot;)<br> strConn = &quot;DSN=Training;uid=;pwd=;&quot;<br> objConn.open strConn<br><br>&nbsp;<br>'put employee answers into database<br>&nbsp;&nbsp;&nbsp;&nbsp;For Index2 = 0 To 19<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strSQL = &quot;UPDATE Answers set Ques_&quot; & (Index2 + 1) & &quot;= '&quot; & request(&quot;Answer&quot; & Index2) & &quot;' where No_Employe = &quot; & EmpNo<br>&nbsp;&nbsp;&nbsp; objConn.Execute strSQL<br> response.write request(&quot;Answer&quot; & Index2)<br>&nbsp;&nbsp;&nbsp;Next<br>objConn.close <br>set objConn = Nothing<br><br><br>the response.write statement is there for error checking, and it prints the correct information.&nbsp;&nbsp;Please let me know if you see why this is not working.<br><br>Thanks<br>
 
The syntax seems fine. Comment out the objConn.Execute strSQL and before it write 'Response.write strSQL.' Check out what SQL statement is being formed. Is it correct, is it grabbing all the right places, etc. Could be a field number problem, could be not grabbing an EmpNo. <br>Once the SQL statement prints on the browser screen see if you can go to SQL server or Access(whatever database you're using) and execute the same query that way. <br>&nbsp;
 
thanks so much Luv!&nbsp;&nbsp;It works now&nbsp;&nbsp;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top