Salve ragazzi sto importando dei dati dentro sql server 2005 da un file txt. Funziona tutto ad eccezione dell'inserimento della da che nel file è nel formato 16-12-09.
Il campo nel db è "datetime".
Questo è il codice:
L'errore che ho è il seguente:codice:<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <% Dim conn, fs, objFile, objFileTextStream, i, strSQL, fsoMyFile Dim strLine, strLinePart, strSaluto, strNome, strCognome, strNumeroSocio, strIndirizzo, strCap, strCitta, strProvincia, strPrefisso, strTelefono, strEmail, strEta, strModello, strData, strDataIns, strDataInsDef, strMatricola1, strMatricola2, strRivenditore, strLocalita, strCommenti, strPrivacy, strEta2 Set fs = Server.CreateObject("Scripting.FileSystemObject") Set objFile = fs.OpenTextFile(Server.MapPath("test.TXT"), 1) conta=0 Do While objFile.AtEndOfStream <> True strLine = objFile.ReadLine if conta>0 then strLinePart = split(strLine, vbTab) for i = 0 TO UBound(strLinePart) If i = 0 Then strSaluto = Trim(strLinePart(i)) ElseIf i = 1 Then strNumeroSocio = Trim(strLinePart(i)) ElseIF i = 2 Then strNome = Trim(strLinePart(i)) ...... strModello = Trim(strLinePart(i)) ElseIF i = 13 Then strData = Trim(strLinePart(i)) ......... ElseIF i = 20 Then strEta2 = Trim(strLinePart(i)) End If Next 'response.write strLine & "</br>" strIndirizzo=Replace(strIndirizzo,"'"," ") strData=Replace(strData,"-","/") strDataIns = CDate(strData) strDataInsDef = kaos_date("%y/%M/%D", strDataIns) response.Write strDataInsDef ' strNumeroSocio = int(strNumeroSocio) Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Driver={SQL Server}; Server=localhost; Database=xxxx; Uid=xxxx; Pwd=xxxx;" SqlInsert = "SELECT numeroSocio, nome, cognome FROM dimension WHERE numeroSocio = '" & strNumeroSocio & "' AND nome = '" & strNome & "' AND cognome = '" & strCognome & "'" Set rsInsert = Conn.Execute(SqlInsert) If rsInsert.EOF Then strSQL = "INSERT INTO dimension (numeroSocio, saluto, nome, cognome, indirizzo, cap, citta, provincia, prefisso, telefono, email, eta, modello, data, matricola1, matricola2, rivenditore, localita, commenti, privacy, eta2) Values('"&strNumeroSocio&"', '"&strSaluto&"','"&strNome&"','"&strCognome&"','"&strIndirizzo&"','"&strCap&"','"&strCitta&"','"&strProvincia&"','"&strPrefisso&"','"&strTelefono&"','"&strEmail&"','"&strEta&"','"&strModello&"',#"&strDataInsDef&"#, '"&strMatricola1&"','"&strMatricola2&"','"&strRivenditore&"','"&strLocalita&"','"&strCommenti&"','"&strPrivacy&"','"&strEta2&"')" response.write strSQL 'conn.Execute strSQL Set RECdown = CreateObject("ADODB.Recordset") set RECdown = conn.execute(strSQL) Else Response.Write strNumeroSocio & "" & strNome & "" & strCognome Response.Write(" è già presente nel database. ") End If rsInsert.Close Set rsInsert = Nothing end if conta=conta+1 Loop objFile.Close Set objFile = Nothing Set fs = Nothing conn.Close Set conn = Nothing %>
Non capisco perchè mi da errore, la query di inserimento sembra corretta.codice:INSERT INTO dimension (numeroSocio, saluto, nome, cognome, indirizzo, cap, citta, provincia, prefisso, telefono, email, eta, modello, data, matricola1, matricola2, rivenditore, localita, commenti, privacy, eta2) Values('xxx', 'xxxx','xxx','xxxx','xxx','xxxx','xxxx','xx','xxxx','xxxx','xxxx','26-34','xxxx',#27/11/09#, 'xxxx','','xxxx','xxxxx','xxxxx','xxxx','xxx') Microsoft OLE DB Provider for ODBC Drivers error '80040e14' [Microsoft][ODBC SQL Server Driver][SQL Server]The name "#27" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
:master:

Rispondi quotando