Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Couldn't update database


Message #1 by "Yvonne" <yenwan77@y...> on Wed, 17 Jul 2002 10:19:07
I am a beginner in ASP. I have a problem with updating records into 
database. Here is part of the code. I guess I'm having problem in 
update.asp where this statement {update_SQL = "UPDATE ReplyData SET Atten 
= '" & atten & "' WHERE NewIC = '" & Request.Form("txtnewic") & "'"} could 
not update the value atten into the database. It could update when I 
replace the Request.Form("txtnewic") to a value like 551255184563 which is 
in the database.

Anybody can tell me what's wrong with the code. Pls help. I'm stuck ! 
Thanks.

***** form.htm *****

<tr> 
        <td height="39"><font face="Arial,Helvetica,Geneva,Swiss,SunSans-
Regular"><b>Please 
          Enter Your New or Old IC Number</b></font></td>
      </tr>
      <tr> 
        <td> 
          <form action="login.asp" method="post">
            <table border="0" cellpadding="0" cellspacing="2" width="580">
              <tr> 
                <td width="124" height="15">&nbsp;</td>
                <td colspan="2" height="15">&nbsp;</td>
              </tr>
              <tr> 
                <td nowrap width="124"><font size="2" face="Verdana, 
Arial, Helvetica, sans-serif">New IC :</font> 
                    
                  <td colspan="2"><font face="Verdana, Arial, Helvetica, 
sans-serif" size="2"> 
                  <input name="txtnewic" size="12" >
                  </font></td>
               
		<tr> 
                <td colspan="3"> 
                  <div align="center"><font face="Verdana, Arial, 
Helvetica, sans-serif" size="2"> 
                    </font><font face="Verdana, Arial, Helvetica, sans-
serif" size="2"> 
                    <input type="submit" value="Login" name="btnSubmit">
                    </font></div>
                </td>
              </tr>

***** login.asp *****

<%
     'Define variables
     Dim newic
    
     newic = Request.Form("txtnewic")
          
     'Set connection
     Dim conn
     Set conn = Server.CreateObject ("ADODB.Connection")
     conn.Open = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
			Server.MapPath("/test/ReplyData.mdb")
	
     'Set recordset
     Dim rs
     Set rs = Server.CreateObject("ADODB.Recordset")
     
    strSQL = "SELECT * FROM ReplyData " _
	& "WHERE NewIC='" & Request.Form("txtnewic") & "'"

     
     rs.Open strSQL, "DSN=ReplyData"
	 rs.MoveFirst
	 
	    Do While Not rs.EOF
		If newic = rs("NewIC") Then %>
		  
		   <td height="419"> 
           
           <form action="update.asp" method="post" >
                     
           <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
</font> 
           <table border="0" cellpadding="0" cellspacing="2" width="580">
			  
			  <tr> 
                <td width="149"><font size="2" face="Verdana, Arial, 
Helvetica, sans-serif">
                  Name :</td>
                 <td><font face="Verdana, Arial, Helvetica, sans-serif" 
size="2"></font><B><%=rs("Name")%></B></td>
			</tr>
              
              <tr> 
                <td nowrap width="149"><font face="Verdana, Arial, 
Helvetica, sans-serif" size="2">New 
                  IC :</font></td>
                <td><font face="Verdana, Arial, Helvetica, sans-serif" 
size="2"> 
                  </font><font face="Verdana, Arial, Helvetica, sans-
serif" size="2"></font><B><%=rs("NewIC")%></B></td>
              </tr>
              

		<td width="34%" height="22"><font face="Verdana, Arial, 
Helvetica, sans-serif" size="2"> 
                 <input type="checkbox" name="chkAtten" value="-1" <%If rs
("Atten")=True Then%>CHECKED<%End If%>>
                  Attend</font></td>

	<div align="center"><br>
            <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
            <input type="submit" value="Submit" name="submit">
            <input type="reset" value="Cancel" name="submit2">
            </font> </div>


**** update.asp *****

	If Request.Form("chkAtten") = "-1" Then
		atten = "-1"
		update_SQL = "UPDATE ReplyData SET Atten = '" & atten & "' 
WHERE NewIC = '" & Request.Form("txtnewic") & "'"
		conn.Execute(update_SQL)
	Else
		atten = "0"
	End If
Message #2 by "Larry Woods" <larry@l...> on Wed, 17 Jul 2002 05:01:46 -0700
Yvonne,

It looks like the NewIC field might be defined as a number field.
If so, then you can't put single-quotes around the value in the
UPDATE statement.  That's for strings or dates (SQL Server).

Hope this helps...

Larry Woods - MCSD, MCT

> -----Original Message-----
> From: Yvonne [mailto:yenwan77@y...]
> Sent: Wednesday, July 17, 2002 10:19 AM
> To: Access ASP
> Subject: [access_asp] Couldn't update database
>
>
> I am a beginner in ASP. I have a problem with updating
> records into
> database. Here is part of the code. I guess I'm having
> problem in
> update.asp where this statement {update_SQL = "UPDATE
> ReplyData SET Atten
> = '" & atten & "' WHERE NewIC = '" &
> Request.Form("txtnewic") & "'"} could
> not update the value atten into the database. It could
> update when I
> replace the Request.Form("txtnewic") to a value like
> 551255184563 which is
> in the database.
>
> Anybody can tell me what's wrong with the code. Pls
> help. I'm stuck !
> Thanks.
>
> ***** form.htm *****
>
> <tr>
>         <td height="39"><font
> face="Arial,Helvetica,Geneva,Swiss,SunSans-
> Regular"><b>Please
>           Enter Your New or Old IC Number</b></font></td>
>       </tr>
>       <tr>
>         <td>
>           <form action="login.asp" method="post">
>             <table border="0" cellpadding="0"
> cellspacing="2" width="580">
>               <tr>
>                 <td width="124" height="15">&nbsp;</td>
>                 <td colspan="2" height="15">&nbsp;</td>
>               </tr>
>               <tr>
>                 <td nowrap width="124"><font size="2"
> face="Verdana,
> Arial, Helvetica, sans-serif">New IC :</font>
>
>                   <td colspan="2"><font face="Verdana,
> Arial, Helvetica,
> sans-serif" size="2">
>                   <input name="txtnewic" size="12" >
>                   </font></td>
>
> 		<tr>
>                 <td colspan="3">
>                   <div align="center"><font
> face="Verdana, Arial,
> Helvetica, sans-serif" size="2">
>                     </font><font face="Verdana, Arial,
> Helvetica, sans-
> serif" size="2">
>                     <input type="submit" value="Login"
> name="btnSubmit">
>                     </font></div>
>                 </td>
>               </tr>
>
> ***** login.asp *****
>
> <%
>      'Define variables
>      Dim newic
>
>      newic = Request.Form("txtnewic")
>
>      'Set connection
>      Dim conn
>      Set conn = Server.CreateObject ("ADODB.Connection")
>      conn.Open = "Provider=Microsoft.Jet.OLEDB.4.0;
> Data Source=" & _
> 			Server.MapPath("/test/ReplyData.mdb")
>
>      'Set recordset
>      Dim rs
>      Set rs = Server.CreateObject("ADODB.Recordset")
>
>     strSQL = "SELECT * FROM ReplyData " _
> 	& "WHERE NewIC='" & Request.Form("txtnewic") & "'"
>
>
>      rs.Open strSQL, "DSN=ReplyData"
> 	 rs.MoveFirst
>
> 	    Do While Not rs.EOF
> 		If newic = rs("NewIC") Then %>
>
> 		   <td height="419">
>
>            <form action="update.asp" method="post" >
>
>            <font size="2" face="Verdana, Arial,
> Helvetica, sans-serif">
> </font>
>            <table border="0" cellpadding="0"
> cellspacing="2" width="580">
>
> 			  <tr>
>                 <td width="149"><font size="2"
> face="Verdana, Arial,
> Helvetica, sans-serif">
>                   Name :</td>
>                  <td><font face="Verdana, Arial,
> Helvetica, sans-serif"
> size="2"></font><B><%=rs("Name")%></B></td>
> 			</tr>
>
>               <tr>
>                 <td nowrap width="149"><font
> face="Verdana, Arial,
> Helvetica, sans-serif" size="2">New
>                   IC :</font></td>
>                 <td><font face="Verdana, Arial,
> Helvetica, sans-serif"
> size="2">
>                   </font><font face="Verdana, Arial,
> Helvetica, sans-
> serif" size="2"></font><B><%=rs("NewIC")%></B></td>
>               </tr>
>
>
> 		<td width="34%" height="22"><font
> face="Verdana, Arial,
> Helvetica, sans-serif" size="2">
>                  <input type="checkbox"
> name="chkAtten" value="-1" <%If rs
> ("Atten")=True Then%>CHECKED<%End If%>>
>                   Attend</font></td>
>
> 	<div align="center"><br>
>             <font face="Verdana, Arial, Helvetica,
> sans-serif" size="2">
>             <input type="submit" value="Submit" name="submit">
>             <input type="reset" value="Cancel" name="submit2">
>             </font> </div>
>
>
> **** update.asp *****
>
> 	If Request.Form("chkAtten") = "-1" Then
> 		atten = "-1"
> 		update_SQL = "UPDATE ReplyData SET Atten
> = '" & atten & "'
> WHERE NewIC = '" & Request.Form("txtnewic") & "'"
> 		conn.Execute(update_SQL)
> 	Else
> 		atten = "0"
> 	End If


  Return to Index