Avatar billede random Nybegynder
10. september 2004 - 14:17 Der er 7 kommentarer og
1 løsning

Hent fra en database og gem i en anden!

Jeg skal have hentet data fra en DB, som skal ligges over i en anden - hvad gør jeg forkert?

Her er koderne!


<%

Dim ID
ID = REQUEST.QUERYSTRING("A_ID")
C_ID = REQUEST.QUERYSTRING("C_ID")

set rs = Server.CreateObject("ADODB.Recordset")
strSQL= "SELECT * FROM "& TB_ARTICLE_SKRIBENT & " WHERE ARTICLE_ID = " & ID
rs.open strSQL,strDNS
   
Dim content, name, p_id, place, Template, sortby, level, parent, cat
content = RS("ARTICLE_CONTENT")
subject = RS("ARTICLE_SUBJECT")
author = RS("ARTICLE_AUTHOR")
email = RS("ARTICLE_EMAIL")
desc = RS("ARTICLE_DESC")
cat = RS("CAT_ID")
picture = RS("ARTICLE_PICTURE")
homepage = RS("ARTICLE_HOMEPAGE")
url = RS("ARTICLE_URL")
ClientID = RS("CLIENT_ID")

relname1 = RS("ARTICLE_LINKSNAME1")
relname2 = RS("ARTICLE_LINKSNAME2")
relname3 = RS("ARTICLE_LINKSNAME3")
relname4 = RS("ARTICLE_LINKSNAME4")
relname5 = RS("ARTICLE_LINKSNAME5")

relurl1 = RS("ARTICLE_LINKSURL1")
relurl2 = RS("ARTICLE_LINKSURL2")
relurl3 = RS("ARTICLE_LINKSURL3")
relurl4 = RS("ARTICLE_LINKSURL4")
relurl5 = RS("ARTICLE_LINKSURL5")

reltarget1 = RS("ARTICLE_LINKSTARGET1")
reltarget2 = RS("ARTICLE_LINKSTARGET2")
reltarget3 = RS("ARTICLE_LINKSTARGET3")
reltarget4 = RS("ARTICLE_LINKSTARGET4")
reltarget5 = RS("ARTICLE_LINKSTARGET5")

function replaceit(str)
       
    str = replace(str, "<STRONG>", "<b>")
    str = replace(str, "</STRONG>", "</b>")
    str = replace(str, "<EM>", "<i>")
    str = replace(str, "</EM>", "</i>")
    str = Replace(str,"'","''")
   
    replaceit = str

end function

Content = replaceit(Content)

subject = Replace(subject, """", "&quot;")
subject = Replace(subject,"'","''")


strSQL = "INSERT INTO " & TB_ARTICLE & " (ARTICLE_SUBJECT, ARTICLE_CONTENT, ARTICLE_DESC, ARTICLE_AUTHOR, ARTICLE_EMAIL, ARTICLE_HOMEPAGE, ARTICLE_URL, CAT_ID, CLIENT_ID, ARTICLE_PICTURE, "
strSQL = strSQL & " ARTICLE_LINKSNAME1, ARTICLE_LINKSNAME2, ARTICLE_LINKSNAME3, ARTICLE_LINKSNAME4, ARTICLE_LINKSNAME5,"
strSQL = strSQL & " ARTICLE_LINKSURL1, ARTICLE_LINKSURL2,  ARTICLE_LINKSURL3,  ARTICLE_LINKSURL4,  ARTICLE_LINKSURL5, "
strSQL = strSQL & " ARTICLE_LINKSTARGET1, ARTICLE_LINKSTARGET2,  ARTICLE_LINKSTARGET3,  ARTICLE_LINKSTARGET4,  ARTICLE_LINKSTARGET5"
strSQL = strSQL & ")"
strSQL = strSQL & "VALUES ('" & subject & "', '" & content & "', '" & desc & "', '" & author & "', '" & email & "', '" & homepage & "', '" & url & "', '" & cat & "', '" & ClientID & "', '" & picture & "', "
strSQL = strSQL & " '" & relname1 & "', '" & relname2 & "', '" & relname3 & "', '" & relname4 & "', '" & relname5 & "',"
strSQL = strSQL & " '" & relurl1 & "', '" & relurl2 & "', '" & relurl3 & "', '" & relurl4 & "', '" & relurl5 & "',"
strSQL = strSQL & " '" & reltarget1 & "', '" & reltarget2 & "', '" & reltarget3 & "', '" & reltarget4 & "', '" & reltarget5 & "'"
strSQL = strSQL & ")"
response.write strSQL
rs.close
set rs=nothing
response.write ("DONE")
'------------------------------------------------------------------------------------------------

set rs2 = Server.CreateObject("ADODB.Recordset")
strSQL2 = "UPDATE "& TB_ARTICLE_SKRIBENT & " SET ARTICLE_STATUS = 2 WHERE ARTICLE_ID = " & ID
rs2.open strSQL2,strDNS
   
RESPONSE.REDIRECT ("articleView.asp?C_ID="&C_ID&"")
rs2.close
set rs2=nothing
%>
Avatar billede erikjacobsen Ekspert
10. september 2004 - 14:40 #1
Udfører du din INSERT-sætning?
Avatar billede random Nybegynder
10. september 2004 - 16:57 #2
min INSERT ligger her??

strSQL = "INSERT INTO " & TB_ARTICLE & " (ARTICLE_SUBJECT, ARTICLE_CONTENT, ARTICLE_DESC, ARTICLE_AUTHOR, ARTICLE_EMAIL, ARTICLE_HOMEPAGE, ARTICLE_URL, CAT_ID, CLIENT_ID, ARTICLE_PICTURE, "
strSQL = strSQL & " ARTICLE_LINKSNAME1, ARTICLE_LINKSNAME2, ARTICLE_LINKSNAME3, ARTICLE_LINKSNAME4, ARTICLE_LINKSNAME5,"
strSQL = strSQL & " ARTICLE_LINKSURL1, ARTICLE_LINKSURL2,  ARTICLE_LINKSURL3,  ARTICLE_LINKSURL4,  ARTICLE_LINKSURL5, "
strSQL = strSQL & " ARTICLE_LINKSTARGET1, ARTICLE_LINKSTARGET2,  ARTICLE_LINKSTARGET3,  ARTICLE_LINKSTARGET4,  ARTICLE_LINKSTARGET5"
strSQL = strSQL & ")"
strSQL = strSQL & "VALUES ('" & subject & "', '" & content & "', '" & desc & "', '" & author & "', '" & email & "', '" & homepage & "', '" & url & "', '" & cat & "', '" & ClientID & "', '" & picture & "', "
strSQL = strSQL & " '" & relname1 & "', '" & relname2 & "', '" & relname3 & "', '" & relname4 & "', '" & relname5 & "',"
strSQL = strSQL & " '" & relurl1 & "', '" & relurl2 & "', '" & relurl3 & "', '" & relurl4 & "', '" & relurl5 & "',"
strSQL = strSQL & " '" & reltarget1 & "', '" & reltarget2 & "', '" & reltarget3 & "', '" & reltarget4 & "', '" & reltarget5 & "'"
strSQL = strSQL & ")"

Men der bliver ikke skrevet noget i TB_ARTICLE men den udføre UPDATE "& TB_ARTICLE_SKRIBENT
Avatar billede erikjacobsen Ekspert
10. september 2004 - 18:35 #3
Udfører du din INSERT-sætning?
Avatar billede random Nybegynder
11. september 2004 - 13:33 #4
Øhh jeg forstår dig ikke! Hva mener du?
Avatar billede erikjacobsen Ekspert
11. september 2004 - 13:38 #5
Du laver en streng

  srrSQL="INSERT ..."

men du udfører den ikke.
Avatar billede random Nybegynder
11. september 2004 - 16:48 #6
Skal jeg så gøre sådan??

set rs3 = Server.CreateObject("ADODB.Recordset")
strSQL3 = "INSERT INTO " & TB_ARTICLE & " (ARTICLE_SUBJECT, ARTICLE_CONTENT, ARTICLE_DESC, ARTICLE_AUTHOR, ARTICLE_EMAIL, ARTICLE_HOMEPAGE, ARTICLE_URL, CAT_ID, CLIENT_ID, ARTICLE_PICTURE, "
strSQL = strSQL & " ARTICLE_LINKSNAME1, ARTICLE_LINKSNAME2, ARTICLE_LINKSNAME3, ARTICLE_LINKSNAME4, ARTICLE_LINKSNAME5,"
strSQL = strSQL & " ARTICLE_LINKSURL1, ARTICLE_LINKSURL2,  ARTICLE_LINKSURL3,  ARTICLE_LINKSURL4,  ARTICLE_LINKSURL5, "
strSQL = strSQL & " ARTICLE_LINKSTARGET1, ARTICLE_LINKSTARGET2,  ARTICLE_LINKSTARGET3,  ARTICLE_LINKSTARGET4,  ARTICLE_LINKSTARGET5"
strSQL = strSQL & ")"
strSQL = strSQL & "VALUES ('" & subject & "', '" & content & "', '" & desc & "', '" & author & "', '" & email & "', '" & homepage & "', '" & url & "', '" & cat & "', '" & ClientID & "', '" & picture & "', "
strSQL = strSQL & " '" & relname1 & "', '" & relname2 & "', '" & relname3 & "', '" & relname4 & "', '" & relname5 & "',"
strSQL = strSQL & " '" & relurl1 & "', '" & relurl2 & "', '" & relurl3 & "', '" & relurl4 & "', '" & relurl5 & "',"
strSQL = strSQL & " '" & reltarget1 & "', '" & reltarget2 & "', '" & reltarget3 & "', '" & reltarget4 & "', '" & reltarget5 & "'"
strSQL = strSQL & ")"
rs3.open strSQL3,strDNS
rs3.close

Så får jeg fejlen:
[MySQL][ODBC 3.51 Driver][mysqld-4.0.18-standard-log]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(ARTICLE_SUBJECT, ARTICLE_CONTENT, ARTICLE_DESC, ARTICLE_AUTHOR
Avatar billede loss Nybegynder
12. september 2004 - 13:50 #7
Du skal ikke have rs3.close ved en insert statement
Avatar billede random Nybegynder
12. september 2004 - 13:58 #8
Arhh ok - tak for det :)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester