Olof Johansson Posted January 27, 2005 Share Posted January 27, 2005 Hej jag har ett problem när jag ska uppdatera, lägga till och radera datan i en tabell. Så här ser koderna ut: Uppdatera: <% Set MinConn = Server.CreateObject("Adodb.Connection") MinConn.Open "Driver=mySQL;server=localhost;uid=****;pwd=****;database=****" SQL = "[color="#0000ff"]SELECT[/color] * [color="#0000ff"]FROM[/color] news [color="#0000ff"]WHERE[/color] ID = " & Request.Form("ad") & " " Set Rs = MinConn.execute(SQL) Rs("title") = Request.Form("title") Rs("news") = Request.Form("news") Rs("date2") = Request.Form("date2") Rs("writer") = Request.Form("writer") Rs.[color="#0000ff"]UPDATE[/color] Rs.Close : Set RS = nothing MinConn.Close : Set MinConn = nothing %> Radera: <% Set MinConn = Server.CreateObject("Adodb.Connection") MinConn.Open "Driver=mySQL;server=localhost;uid=****;pwd=****;database=****" SQL = "[color="#0000ff"]SELECT[/color] * [color="#0000ff"]FROM[/color] news [color="#0000ff"]WHERE[/color] ID = " & Request.QueryString("newsid") & " " Set Rs = MinConn.execute(SQL) RS.[color="#0000ff"]DELETE[/color] Rs.Close : Set RS = nothing MinConn.Close : Set MinConn = nothing %> Lägga till: <% Set MinConn = Server.CreateObject("Adodb.Connection") MinConn.Open "Driver=mySQL;server=localhost;uid=****;pwd=****;database=****" SQL = "[color="#0000ff"]SELECT[/color] * [color="#0000ff"]FROM[/color] news" Set Rs = MinConn.execute(SQL) RS.AddNew Rs("date2") = Request.Form("Date2") Rs("Title") = Request.Form("Title") Rs("News") = Request.Form("News") Rs("Writer") = Request.Form("Writer") Rs.[color="#0000ff"]UPDATE[/color] Rs.Close : Set RS = nothing MinConn.Close : Set MinConn = nothing %> Felmeddelandet blir: "ADODB.Recordset.1 (0x80004005) Recordset is read-only" Myyyycket tacksam för snabb hjälp! //Mvh Olof Johansson Link to comment Share on other sites More sharing options...
PJP Posted January 27, 2005 Share Posted January 27, 2005 Hej! Uppdatera: <% Set MinConn = Server.CreateObject("Adodb.Connection") MinConn.Open "Driver=mySQL;server=localhost;uid=****;pwd=****;database=** **" Dim title Dim news Dim date2 Dim writer title = Request.Form("title") news = Request.Form("news") date2 = Request.Form("date2") writer = Request.Form("writer") SQL = "Update news Set " & _ "title='" & title & "', " & _ "news='" & news & "', " & _ "date2='" & date2 & "', " & _ "writer='" & writer & "' Where ID=" & Request.Form("ad") MinConn.execute(SQL) Rs.Close Set RS = nothing MinConn.Close Set MinConn = nothing %> RADERA: SQL = "DELETE From news Where ID=" & Request.Form("ad") MinConn.execute(SQL) INSERT: title = Request.Form("title") news = Request.Form("news") date2 = Request.Form("date2") writer = Request.Form("writer") SQL = "INSERT INTO news(title, news, date2, writer) VALUES('" & _ title & "','" & news & "','" & date2 & "','" & writer & "')" MinConn.execute(SQL) /PJ Link to comment Share on other sites More sharing options...
Olof Johansson Posted January 27, 2005 Author Share Posted January 27, 2005 Task så mycket PJP! Allt fungerar förutom att uppdatera. Får följande fel: "Line splice not followed by a newline" Nån som vet hur man fixar? EDIT* Det funka när jag tog bort alla _ Men då uppdateras t.ex titeln till "title" [inlägget ändrat 2005-01-27 17:31:43 av Olof Johansson] Link to comment Share on other sites More sharing options...
PJP Posted January 27, 2005 Share Posted January 27, 2005 Hej! Prova att skriva allt på en rad... SQL = "Update news Set title='" & title & "', news='" & news & "', date2='" & date2 & "', writer='" & writer & "' Where ID=" & Request.Form("ad") /PJ Link to comment Share on other sites More sharing options...
Olof Johansson Posted January 27, 2005 Author Share Posted January 27, 2005 Tänkte också på det. Prövade det men det fungerade inte Tack för all hjälp hittils Link to comment Share on other sites More sharing options...
PJP Posted January 27, 2005 Share Posted January 27, 2005 Hej igen! Vad fick du för felmeddelande när du skrev allt på samma rad? /PJ Link to comment Share on other sites More sharing options...
Meme Posted January 27, 2005 Share Posted January 27, 2005 Skriv ut din fråga för att se om den ser korrekt ut med all data. Dvs innan du gör uppdatering: Response.Write SQL Response.End Link to comment Share on other sites More sharing options...
Olof Johansson Posted January 27, 2005 Author Share Posted January 27, 2005 Detta va skumt, jag klistra in din senaste kod rakt av och nu funkar det. Kanske hade något tecken nånstans innan jag inte såg. Tack så hemsk mycket för hjälpen! Nu blev hela sidan klar =) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.