Just nu i M3-nätverket
Jump to content

Uppdatera data i databas


Olof Johansson

Recommended Posts

Olof Johansson

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

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

Olof Johansson

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

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

Olof Johansson

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

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...