Les changements ont été faits. Et merci! La page s'affiche correctement, soit:
INSERT INTO tableeve (date, titre, entree, entree2, entree3) VALUES ('5/22/2002', 'rtret', 'tretre', 'tretre', 'tretre' );
Thanks for submitting your information to us!
The resulting SQL statement was:
INSERT INTO tableeve (date, titre, entree, entree2, entree3)
VALUES ('5/22/2002', 'rtret', 'tretre', 'tretre', 'tretre' );
Number of records affected:
Mais cela ne s'enregistre pas dans la bd?
Je ne ferais pas exécuter la requête?
Code entier:
<!-- #include file="adovbs.inc" -->
<%
' *** Begin DB Setup ***
Dim strConnString
' Sample access OLEDB CONN String.
Set RS = Server.CreateObject ("ADODB.RecordSet")
Set ConnString = Server.CreateObject("ADODB.Connection")
ConnString.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\lesjoursdeeve\db\eve.mdb"))
Const DATE_DELIMITER = "'"
' *** End DB Setup ***
Dim RS ' CONN object
Dim strSQL ' String in which to build our SQL command
Dim lngRecsAffected ' # of records affected... just informational
Dim datquand
Dim strtitre
Dim strentree
Dim strentree2
Dim strentree3
Dim strErrorMsg ' Holds error message if we catch any problems.
' See if we have any info to process.
' If we don't (ie. the first time through) we just show
' the form. If we do we proceed with the insert.
If Request.Form("action") <> "Save Form Data" Then
' Show the form
%>
<form action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="POST" name="Saisie_eve">
<input type="hidden" name="action" value="Save Form Data" />
PROBLEME JUSTE ICI EN HAUT????
<div align="center">
<table border="1" cellpadding="10" cellspacing="0" width="50%" bordercolor="#000080">
<tr>
<td width="22%" bgcolor="#CAE4FF"><font face="Arial" size="2">quand</font></td>
<td width="78%"><input type="text" name="quand" size="8"></td>
</tr>
<tr>
<td width="22%" bgcolor="#CAE4FF"><font face="Arial" size="2">titre<font></td>
<td width="78%"><input type="text" name="titre" size="70"></td>
</tr>
<tr>
<td width="22%" bgcolor="#CAE4FF"><font face="Arial" size="2">entree</font></td>
<td width="78%"><textarea rows="10" name="entree" cols="75"></textarea></td>
</tr>
<tr>
<td width="22%" bgcolor="#CAE4FF"><font face="Arial" size="2">entree</font></td>
<td width="78%"><textarea rows="10" name="entree2" cols="75"></textarea></td>
</tr>
<tr>
<td width="22%" bgcolor="#CAE4FF"><font face="Arial" size="2">entree</font></td>
<td width="78%"><textarea rows="10" name="entree3" cols="75"></textarea></td>
</tr>
<td> </td>
<td>
<input type="reset" value="Clear" />
<input type="submit" value="Save" />
</td>
</tr>
</table>
</form>
<%
Else
' Do our DB insert!
' Retrieve the 5 strings to be entered into the DB
datquand = Request.Form("quand")
strtitre = Request.Form("titre")
strentree = Request.Form("entree")
strentree2 = Request.Form("entree2")
strentree3 = Request.Form("entree3")
On Error Resume Next
strErrorMsg = ""
' String (text) field:
' Nothing should really go wrong here. It's already a string so
' I don't bother with a CStr. I do replace ' with '' for the
' validity our SQL statement and also check to make sure it's
' not an empty string. If it is an empty string ("") then I
' throw a fake error since I've already got this type of error
' handling in place... hey I already admitted I was lazy!
strtitre = Trim(strtitre)
If Len(strtitre) = 0 Or Len(strtitre) > 10 Then Err.Raise 1
strtitre = Replace(strtitre, "'", "''")
If Err.number <> 0 Then
strErrorMsg = strErrorMsg & "Erreur dans " & _
"titre<br />" & vbCrLf
Err.Clear
End If
strentree = Trim(strentree)
If Len(strentree) = 0 Or Len(strentree) > 10 Then Err.Raise 1
strentree = Replace(strentree, "'", "''")
If Err.number <> 0 Then
strErrorMsg = strErrorMsg & "Erreur dans " & _
"entree<br />" & vbCrLf
Err.Clear
End If
strentree2 = Trim(strentree2)
If Len(strentree2) = 0 Or Len(strentree2) > 10 Then Err.Raise 1
strentree2 = Replace(strentree2, "'", "''")
If Err.number <> 0 Then
strErrorMsg = strErrorMsg & "Erreur dans " & _
"entree2<br />" & vbCrLf
Err.Clear
End If
strentree3 = Trim(strentree3)
If Len(strentree3) = 0 Or Len(strentree3) > 10 Then Err.Raise 1
strentree3 = Replace(strentree3, "'", "''")
If Err.number <> 0 Then
strErrorMsg = strErrorMsg & "Erreur dans " & _
"entree3<br />" & vbCrLf
Err.Clear
End If
datquand = CDate(datquand)
If Err.number <> 0 Then
strErrorMsg = strErrorMsg & "Your entry for date_time_field could " & _
"not be converted to an date variable!<br />" & vbCrLf
Err.Clear
End If
On Error Goto 0
' If we have an error in our error string then we show
' the error message o/w we proceed with the insert.
If strErrorMsg <> "" Then
' Show the error message that got us here!
Response.Write strErrorMsg
Else
' Open connection to the DB
Set cnnFormToDB = Server.CreateObject("ADODB.Connection")
cnnFormToDB.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\lesjoursdeeve\db\eve.mdb"))
' Build our SQL String
strSQL = ""
strSQL = strSQL & "INSERT INTO tableeve "
strSQL = strSQL & "(date, titre, entree, entree2, entree3) " & vbCrLf
strSQL = strSQL & "VALUES ("
strSQL = strSQL & DATE_DELIMITER & datquand & DATE_DELIMITER
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strtitre & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strentree & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strentree2 & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strentree3 & "'"
strSQL = strSQL & " );"
Response.Write strSQL & "<br>" & vbCrLf
' Execute the SQL command. I pass it a variable lngRecsAffected
' in which to return the number of records affected. I also tell
' it that this is a text command and it won't be returing any
' records... this helps it execute the script faster!
' And before you ask... I don't know, but YES IT IS OR!!!
'cnnFormToDB.Execute strSQL, lngRecsAffected, adCmdText Or adExecuteNoRecords
' Dispose of the CONN object
cnnFormToDB.Close
Set cnnFormToDB = Nothing
' Display a verification message and we're done!
%>
<h2>Thanks for submitting your information to us!</h2>
<p>
<strong>The resulting SQL statement was:</strong>
<pre><%= strSQL %></pre>
</p>
<p>
<strong>Number of records affected:</strong> <%= lngRecsAffected %>
</p>
<%
End If
End If
%>
J'ai indiqué en lettres capitales où le problème pourrait être: une mauvaise appellation de noms de fichiers? Mais je ne m'y connais que très peu...
Merci, si cela vous est facile, de trouver le problème!!
Eve