Nous sommes actuellement le 29 Mars 2024, 11:48

Le fuseau horaire est UTC-5 heures [Heure d’été]




Publier un nouveau sujet Répondre au sujet  [ 7 message(s) ] 
Auteur Message
MessagePublié: 22 Mai 2002, 14:42 
Hors-ligne
Petit nouveau
Petit nouveau
Avatar de l’utilisateur

Inscription : 19 Mars 2002, 11:53
Message(s) : 38
L'ordi me dit qu'il y a une erreur dans ce bout de code (et sûrement ailleurs aussi plus loin :? ):


Set cnnFormToDB = Server.CreateObject("ADODB.Connection")
cnnFormToDB.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("..\eve.mdb"))

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 & " );"

cnnFormToDB.Execute strSQL, lngRecsAffected, adCmdText Or adExecuteNoRecords

cnnFormToDB.Close
Set cnnFormToDB = Nothing


Plus haut dans le code, il y a l'ouverture de la connection, le formulaire.
Et plus bas de ce code, un message qui confirme la prise en compte de l'ajout.

Voyez-vous ce qui cloche?


Merci d'avance :)

Eve


Haut
 Profil  
Répondre en citant  
 Sujet du message:
MessagePublié: 22 Mai 2002, 16:08 
Hors-ligne
Fidèle
Fidèle
Avatar de l’utilisateur

Inscription : 07 Jan 2002, 22:14
Message(s) : 790
Localisation : Extrémité sud-ouest de Lévis
Pourriez-vous écrire le message d'erreur ? Je ne suis actuellement en mseure de vous répondre.


Haut
 Profil  
Répondre en citant  
 Sujet du message:
MessagePublié: 22 Mai 2002, 16:15 
Hors-ligne
Petit nouveau
Petit nouveau
Avatar de l’utilisateur

Inscription : 19 Mars 2002, 11:53
Message(s) : 38
Je savais que j'oubliais un détail, zut!




Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

/lesjoursdeeve/db/enregistrement_eve.asp, line 189


Voilà!


Eve


Haut
 Profil  
Répondre en citant  
 Sujet du message:
MessagePublié: 22 Mai 2002, 16:32 
Hors-ligne
Fidèle
Fidèle
Avatar de l’utilisateur

Inscription : 07 Jan 2002, 22:14
Message(s) : 790
Localisation : Extrémité sud-ouest de Lévis
La chaîne SQL me semble correcte. Pour en être certain, écrivez ceci après la série de concaténations :
Code :
Response.Write strSQL & "<br>" & vbCrLf


puis mettez en commentaire la ligne
Code :
cnnFormToDB.Execute strSQL, lngRecsAffected, adCmdText Or adExecuteNoRecords


EDIT : Copiez ce qui sera affiché par la prmière ligne de code dans votre réponse.


Haut
 Profil  
Répondre en citant  
 Sujet du message:
MessagePublié: 23 Mai 2002, 11:51 
Hors-ligne
Petit nouveau
Petit nouveau
Avatar de l’utilisateur

Inscription : 19 Mars 2002, 11:53
Message(s) : 38
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>&nbsp;</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


Haut
 Profil  
Répondre en citant  
 Sujet du message:
MessagePublié: 23 Mai 2002, 14:41 
Hors-ligne
Fidèle
Fidèle
Avatar de l’utilisateur

Inscription : 07 Jan 2002, 22:14
Message(s) : 790
Localisation : Extrémité sud-ouest de Lévis
C'est normal que cela ne s'ajoute pas à la base de données, l'instruction qui la fait ajouter est en commentaire.

La chaîne SQL me semble valide. Peut-être que la date doit être en format américain soit mm/jj/aaaa.

Essayez la méthode d'ajout sans les paramètres supplémentaires:
cnnFormToDB.Execute strSQL ', lngRecsAffected ', adCmdText Or adExecuteNoRecords

ensuite
cnnFormToDB.Execute strSQL, lngRecsAffected ', adCmdText Or adExecuteNoRecords


Haut
 Profil  
Répondre en citant  
 Sujet du message:
MessagePublié: 23 Mai 2002, 14:59 
Hors-ligne
Petit nouveau
Petit nouveau
Avatar de l’utilisateur

Inscription : 19 Mars 2002, 11:53
Message(s) : 38
Merci beaucoup! Ca a marché!

Et il restait une erreur à moi aussi (un nom de colonne dans la bd qui était mal nommé dans la requête).

Bon, maintenant, je vais construire la page pour détruire cette fausse entrée! Je vais peut-être revenir faire un petit tour ici éventuellement... ;)


Eve qui est heureuse!


Haut
 Profil  
Répondre en citant  
Afficher les messages publiés depuis :  Trier par  
Publier un nouveau sujet Répondre au sujet  [ 7 message(s) ] 

Le fuseau horaire est UTC-5 heures [Heure d’été]


Qui est en ligne ?

Utilisateur(s) parcourant ce forum : Aucun utilisateur inscrit et 8 invité(s)


Vous ne pouvez pas publier de nouveaux sujets dans ce forum
Vous ne pouvez pas répondre aux sujets dans ce forum
Vous ne pouvez pas éditer vos messages dans ce forum
Vous ne pouvez pas supprimer vos messages dans ce forum

Recherche de:
Aller vers :  
Propulsé par phpBB® Forum Software © phpBB Group
Traduction et support en françaisHébergement de site