Mon pb est pour le champ LCAUSE. En effet dans ce champ il y a des D' et des L'. Or sql ne peut les insérer dans la base. C'est pour cela que j'ai essayé le replace mais ça ne marche toujours pas.
Que dois je faire? Est ce que mes replace sont mals écrits ou mal positionnés dans le script?
Voilà mon script:
<%
Dim FichierExcel, MaConn, MonObjRs, MonSQL, CompteurColonne
'Nom du fichier Xls
FichierExcel = "renault.xls"
' Création de la connexion
Set MaConn = Server.CreateObject("ADODB.Connection")
MaConn.Open "DBQ=" & Server.MapPath(FichierExcel) & ";DRIVER={Microsoft Excel Driver (*.xls)};"
Set MonObjRs = Server.CreateObject("ADODB.Recordset")
' Requete sur le fichier excel
' ATTENTION, c'est le nom d'une zone, regardez dans ' le fichier xls pour voir ce dont je parle
' La Zone s'appelle "renault", la requete ne se fait pas sur
' la feuille mais sur une zone
MonSQL = "SELECT * FROM renault;"
' Exécution de la requête
MonObjRs.Open MonSQL, MaConn%>
<%
If Request.Form("cause") Then
LCAUSE=Request.Form("LCAUSE")
LCAUSE=Replace(LCAUSE,"'","''")
LCAUSE=Replace(LCAUSE,"<","<")
LCAUSE=Replace(LCAUSE,">",">")
LCAUSE=Replace(LCAUSE,vbCrLf,"<br>")
' Requête permettant l'insertion des éléments provenant du fichier excel vers la table renault
If Request.Form("action")<>"" then
SQL = "INSERT INTO Renault(NORDRE, CFOU, CADRES, DESFOU, VILLE, NPIE, DESPIE, FAMACH, PROJET, SAH, LUSINECR, CUSINE, LTECUSI, TINCID, DINCID, QTENC, LACTDEM, CVEHORG, CCAUSE, LCAUSE, QDEMTOT) VALUES('" & Request.Form("NORDRE1") & "', '" & Request.Form("CFOU1") & "', '" & Request.Form("CADRES1") & "', '" & Request.Form("DESFOU1") & "', '" & Request.Form("VILLE1") & "', '" & Request.Form("NPIE1") & "', '" & Request.Form("DESPIE1") & "', '" & Request.Form("FAMACH1") & "', '" & Request.Form("PROJET1") & "', '" & Request.Form("SAH1") & "', '" & Request.Form("LUSINECR1") & "', '" & Request.Form("CUSINE1") & "', '" & Request.Form("LTECUSI1") & "', '" & Request.Form("TINCID1") & "', '" & Request.Form("DINCID1") & "', '" & Request.Form("QTENC1") & "', '" & Request.Form("LACTDEM1") & "', '" & Request.Form("CVEHORG1") & "', '" & Request.Form("CCAUSE1") & "', '" & Request.Form("LCAUSE") & "', '" & Request.Form("QDEMTOT1") & "')"
If not NB_Conn.query(SQL) Then MySQLError(NB_Conn)
Response.Redirect "renault3.asp"
End If
End If
%>
<html>
<head>
<title>Test du transfert des données d'un fichier excel vers la base SQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/include/style.css" type="text/css">
<link rel="stylesheet" href="/include/style.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!--#include virtual="/include/haut.html" -->
<h2 align="center">Test du transfert des données d'un fichier excel vers la base SQL</h2>
<table border="1" cellspacing="0" cellpadding="2" align="center" bordercolor="#000000">
<tr>
<td colspan="8"><font face="Verdana" size="2" color="#0000FF">
<b>Contenue du fichier renault.xls dans une page WEB</b></font>"</td>
</tr>
<tr>
<%For CompteurColonne = 0 To (MonObjRs.Fields.Count - 1)%>
<td bgcolor="#C0C0C0"><b><font face="Verdana" size="2">
<% ' Le nom des champs %>
<%=MonObjRs.Fields.Item(CompteurColonne).Name%></font></b></td>
<%Next%>
</tr>
<%Do While Not MonObjRs.EOF%>
<form method="post" action="">
<tr>
<td align="center"><font face="Arial" size="2">
<input type="text" name="NORDRE1" value="<%=MonObjRs.Fields.Item(0).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="CFOU1" value="<%=MonObjRs.Fields.Item(1).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="CADRES1" value="<%=MonObjRs.Fields.Item(2).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="DESFOU1" value="<%=MonObjRs.Fields.Item(3).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="VILLE1" value="<%=MonObjRs.Fields.Item(4).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="NPIE1" value="<%=MonObjRs.Fields.Item(5).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="DESPIE1" value="<%=MonObjRs.Fields.Item(6).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="FAMACH1" value="<%=MonObjRs.Fields.Item(7).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="PROJET1" value="<%=MonObjRs.Fields.Item(8).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="SAH1" value="<%=MonObjRs.Fields.Item(9).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="LUSINECR1" value="<%=MonObjRs.Fields.Item(10).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="CUSINE1" value="<%=MonObjRs.Fields.Item(11).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="LTECUSI1" value="<%=MonObjRs.Fields.Item(12).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="TINCID1" value="<%=MonObjRs.Fields.Item(13).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="DINCID1" value="<%=MonObjRs.Fields.Item(14).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="QTENC1" value="<%=MonObjRs.Fields.Item(15).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="LACTDEM1" value="<%=MonObjRs.Fields.Item(16).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="CVEHORG1" value="<%=MonObjRs.Fields.Item(17).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="CCAUSE1" value="<%=MonObjRs.Fields.Item(18).Value %>"></font></td>
<td align="center"><font face="Arial" size="2">
<input type="hidden" name="cause" value="True">
<textarea name="LCAUSE" cols="30" rows="1" ><%=MonObjRs.Fields.Item(19).Value %></textarea>
</font></td>
<td align="center"><font face="Arial" size="2">
<input type="text" name="QDEMTOT1" value="<%=MonObjRs.Fields.Item(20).Value %>">
<input type="hidden" name="action" value="ajout"></font></td>
<Td><center><input type="submit" name="Submit" value="Ajouter le site"></center></Td>
</tr>
</form>
<%MonObjRs.MoveNext
Loop%>
</table>
<p align="center"><a href="/">[Retour à l'accueil]</a></p>