473,385 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem saving to database

4
I have a form with a list of yes/no questions which records to an Access database. Occasionally a string of 'yes' answers are being recorded as 'no' in the database. For example, the first 3 may record as 'yes' then the remaining questions all record as 'no'.

I have set up tests to check the SQL statements which confirm the data being sent is correct.

The code is posted below.

Any help is appreciated.
Thanks
Graham

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript LCID=2057%>
  2. <% Option Explicit %>
  3. <!-- #include file="adovbs.inc" -->
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "(URL address blocked: See forum rules)">
  6.  
  7. <html>
  8. <head>
  9.     <title></title>
  10. </head>
  11.  
  12.   <h1>Questionnaire</h1>
  13.  
  14. <% 
  15.     ' -- Declare Variables
  16.     Dim Conn, strConn
  17.     Dim strSQL1, strSQL2, strSQL3
  18.     Dim strNTUsername, strComplete, ValidatedForm, ValidationErrorMsg, i, Q
  19.  
  20.     strComplete = "yes"
  21.  
  22.     ' open connection
  23.     Set Conn = Server.CreateObject("ADODB.Connection")
  24.     strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=i:\inetpub\assessment.mdb"
  25.     Conn.Open strConn
  26.  
  27.     ' -- Get the users NTUsername
  28.     strNTUsername = Request.ServerVariables("REMOTE_USER")
  29.     strNTUsername = Right(strNTUsername,len(strNTUsername)-4)
  30.  
  31.    '-- validate form results
  32.   ValidatedForm = true
  33.   ValidationErrorMsg = "<p>You have not completed one or more questions. Please return to the <a href='test_form.asp'>form</a> and answer the following questions:</p><p>"
  34.  
  35.   For i = 1 to 41
  36.     Session("Q" & i) = Request.Form("fmQ" & i)
  37.     Session("fmQ" & i & "Comment") = Request.Form("fmQ" & i & "Comment")     
  38.     Q = Session("Q" & i)
  39.  
  40.     If Q = "" Then
  41.       ValidatedForm = false
  42.       ValidationErrorMsg = ValidationErrorMsg & i & ",*"
  43.     End If  
  44.   Next
  45.  
  46.   ValidationErrorMsg = Left(ValidationErrorMsg,len(ValidationErrorMsg)-7)
  47.  
  48.   If ValidatedForm = false Then
  49.     Response.Write(ValidationErrorMsg & "</p>")
  50.       Else
  51.  
  52.     ' create and open first Recordset using Connection - execute
  53.     strSQL1 = "INSERT INTO tblQuestionnaireResults (NTUsername, DateOfAssessment) VALUES ('" & strNTUsername & "', Now());"
  54.     Conn.Execute(strSQL1)
  55.  
  56.     ' -- Check if an action is required
  57.     For i = 1 to 41      
  58.       Q=Request.Form("fmQ" & i)
  59.       If Q = 0 AND i <> 39 OR Q = 1 AND i = 39 Then
  60.         strComplete = "action"
  61.         Exit For
  62.           Else
  63.         strComplete = "yes"
  64.       End If    
  65.     Next
  66.  
  67.      ' -- Write answers to database 
  68.     For i = 1 to 41
  69.       Q=Request.Form("fmQ" & i)
  70.       If i = 38 AND Q <> 1 Then
  71.         strSQL2 = "UPDATE tblQuestionnaireResults SET Q" & i & " = '" & Q & "', Q38Comment = '" & Request.Form("fmQ38Comment") & "' WHERE NTUsername ='" & strNTUsername & "' AND DateOfAssessment = Now();"
  72.           ElseIf i = 39 AND Q = 1 Then
  73.         strSQL2 = "UPDATE tblQuestionnaireResults SET Q" & i & " = '" & Q & "', Q39Comment = '" & Request.Form("fmQ39Comment") & "' WHERE NTUsername ='" & strNTUsername & "' AND DateOfAssessment = Now();"
  74.           Else
  75.         strSQL2 = "UPDATE tblQuestionnaireResults SET Q" & i & " = '" & Q & "' WHERE NTUsername ='" & strNTUsername & "' AND DateOfAssessment = Now();"
  76.       End If
  77.       Conn.Execute (strSQL2)
  78.     Next
  79.  
  80.       strSQL3 = "UPDATE tblUsers SET Complete = '" & strComplete & "' WHERE NTUsername ='" & strNTUsername & "';"
  81. %>
  82.       <p>Thank you for completing the assessment.</p>
  83.  
  84.  
  85. <% Conn.Execute (strSQL3)
  86.  
  87.    End If
  88.  
  89.    Conn.Close
  90.    Set Conn = Nothing %>
  91.  
  92. </body>
  93. </html>
Dec 15 '06 #1
4 1463
iam_clint
1,208 Expert 1GB
I have a form with a list of yes/no questions which records to an Access database. Occasionally a string of 'yes' answers are being recorded as 'no' in the database. For example, the first 3 may record as 'yes' then the remaining questions all record as 'no'.

I have set up tests to check the SQL statements which confirm the data being sent is correct.

The code is posted below.

Any help is appreciated.
Thanks
Graham

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript LCID=2057%>
  2. <% Option Explicit %>
  3. <!-- #include file="adovbs.inc" -->
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "(URL address blocked: See forum rules)">
  6.  
  7. <html>
  8. <head>
  9.     <title></title>
  10. </head>
  11.  
  12.   <h1>Questionnaire</h1>
  13.  
  14. <% 
  15.     ' -- Declare Variables
  16.     Dim Conn, strConn
  17.     Dim strSQL1, strSQL2, strSQL3
  18.     Dim strNTUsername, strComplete, ValidatedForm, ValidationErrorMsg, i, Q
  19.  
  20.     strComplete = "yes"
  21.  
  22.     ' open connection
  23.     Set Conn = Server.CreateObject("ADODB.Connection")
  24.     strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=i:\inetpub\assessment.mdb"
  25.     Conn.Open strConn
  26.  
  27.     ' -- Get the users NTUsername
  28.     strNTUsername = Request.ServerVariables("REMOTE_USER")
  29.     strNTUsername = Right(strNTUsername,len(strNTUsername)-4)
  30.  
  31.    '-- validate form results
  32.   ValidatedForm = true
  33.   ValidationErrorMsg = "<p>You have not completed one or more questions. Please return to the <a href='test_form.asp'>form</a> and answer the following questions:</p><p>"
  34.  
  35.   For i = 1 to 41
  36.     Session("Q" & i) = Request.Form("fmQ" & i)
  37.     Session("fmQ" & i & "Comment") = Request.Form("fmQ" & i & "Comment")     
  38.     Q = Session("Q" & i)
  39.  
  40.     If Q = "" Then
  41.       ValidatedForm = false
  42.       ValidationErrorMsg = ValidationErrorMsg & i & ",*"
  43.     End If  
  44.   Next
  45.  
  46.   ValidationErrorMsg = Left(ValidationErrorMsg,len(ValidationErrorMsg)-7)
  47.  
  48.   If ValidatedForm = false Then
  49.     Response.Write(ValidationErrorMsg & "</p>")
  50.       Else
  51.  
  52.     ' create and open first Recordset using Connection - execute
  53.     strSQL1 = "INSERT INTO tblQuestionnaireResults (NTUsername, DateOfAssessment) VALUES ('" & strNTUsername & "', Now());"
  54.     Conn.Execute(strSQL1)
  55.  
  56.     ' -- Check if an action is required
  57.     For i = 1 to 41      
  58.       Q=Request.Form("fmQ" & i)
  59.       If Q = 0 AND i <> 39 OR Q = 1 AND i = 39 Then
  60.         strComplete = "action"
  61.         Exit For
  62.           Else
  63.         strComplete = "yes"
  64.       End If    
  65.     Next
  66.  
  67.      ' -- Write answers to database 
  68.     For i = 1 to 41
  69.       Q=Request.Form("fmQ" & i)
  70.       If i = 38 AND Q <> 1 Then
  71.         strSQL2 = "UPDATE tblQuestionnaireResults SET Q" & i & " = '" & Q & "', Q38Comment = '" & Request.Form("fmQ38Comment") & "' WHERE NTUsername ='" & strNTUsername & "' AND DateOfAssessment = Now();"
  72.           ElseIf i = 39 AND Q = 1 Then
  73.         strSQL2 = "UPDATE tblQuestionnaireResults SET Q" & i & " = '" & Q & "', Q39Comment = '" & Request.Form("fmQ39Comment") & "' WHERE NTUsername ='" & strNTUsername & "' AND DateOfAssessment = Now();"
  74.           Else
  75.         strSQL2 = "UPDATE tblQuestionnaireResults SET Q" & i & " = '" & Q & "' WHERE NTUsername ='" & strNTUsername & "' AND DateOfAssessment = Now();"
  76.       End If
  77.       Conn.Execute (strSQL2)
  78.     Next
  79.  
  80.       strSQL3 = "UPDATE tblUsers SET Complete = '" & strComplete & "' WHERE NTUsername ='" & strNTUsername & "';"
  81. %>
  82.       <p>Thank you for completing the assessment.</p>
  83.  
  84.  
  85. <% Conn.Execute (strSQL3)
  86.  
  87.    End If
  88.  
  89.    Conn.Close
  90.    Set Conn = Nothing %>
  91.  
  92. </body>
  93. </html>
whats the error?
Dec 15 '06 #2
sashi
1,754 Expert 1GB
Hi there,

Please provide clear & simple problem / error statement as it would ease in providing solution in return. Good luck & Take care.
Dec 16 '06 #3
twave
4
There is no error message. I am recording the SQL output to a text file to check the results. If I answer yes to all questions on the form, this is the output in the text file:

UPDATE tblQuestionnaireResults SET Q1 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q2 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q3 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q4 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q5 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q6 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q7 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q8 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q9 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q10 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q11 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q12 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q13 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q14 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q15 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q16 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q17 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q18 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q19 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q20 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q21 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q22 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q23 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q24 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q25 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q26 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q27 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q28 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q29 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q30 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q31 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q32 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q33 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q34 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q35 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q36 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q37 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q38 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q39 = '1', Q39Comment = '' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q40 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();
UPDATE tblQuestionnaireResults SET Q41 = '1' WHERE NTUsername ='ntusername' AND DateOfAssessment = Now();

In this instance the database recorded Q1 - Q41 as:

Yes Yes Yes Yes Yes Yes Yes
Yes Yes Yes Yes Yes Yes Yes
Yes Yes Yes Yes Yes Yes Yes
Yes Yes No No No No No
No No No No No No No
No No No No No No

It is not a consistant pattern. The same input has recorded differently in the database. It is always a number of positive answers followed by negative answers. i.e:

Yes Yes Yes No No No No
No No No No No No No
No No No No No No No
No No No No No No No
No No No No No No No
No No No No No No

Most of the time, the same output records correctly in the database.

Thanks for your help.
Dec 18 '06 #4
twave
4
Problem was in SQL statement. 'Now()' changed as it ran through a loop updating fields in the record. If the update completed before the next second started it all got written to the database. Otherwise the WHERE clause didn't match and it didn't write.

I added another SQL statement to get the date from the original record and compare this in the SQL statement instead of 'Now()'.
Dec 20 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
3
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
6
by: BobLewiston | last post by:
When I try to save a new (inserted) record in an SQL database, I get the following System.Runtime.InteropServices.ExternalException message: I have to either find out how to insert an...
2
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.