Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Delete Row 1

Status
Not open for further replies.

MarkZK

Technical User
Jul 13, 2006
202
GB
Hi all,

I'm completely new to working with databases which I'm sure will become apparent in no time.

I'm trying to delete a complete row based on the value of the ID column, here is what I have so far.

Code:
<%
rowid = server.HtmlEncode(request.form("refiddel")) 
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("\Database\data.mdb")
Conn.Open

Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "SELECT * from database1", Conn, 1,3

do while not rs.EOF 
if Rs("dbrowid") = rowid then Rs.Delete
rs.MoveNext 
loop

set Rs = nothing
set Conn = nothing
%>

This will obviously delete the value of the textfield that matches the value of the request.form , but I don't want to have to enter the value of every row that follows to delete it.

Could somebody we databasing know-how show me how to adjust the code to include the entire row, or link me in the right direction.

Thanks.
 
If you are only deleting a record you don't need a Recordset object. You can use the Execute method on the Connection object. You will still need to open and close your connection object of course.
Code:
Conn.Execute "Delete from database1 WHERE dbrowid = rowid

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top