Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Database error when deleting record

Hello,

When I try to delete a record from my database, i get an error. I really don't get wat's wrong with this:

[code]<%
Name = Request.Querystring("Name")
'Database connection
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("data.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = DataConn
rs.CursorType = adOpenKeyset

[b][red]rs.open = "delete * from Sponsors where Name = " & Name[/red][/b]

response.redirect("Sponsors.asp")
%>[/code]

The debug info i get from IIS is this:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access-driver] Not enough parameters. The expected number is: 1.
/BD/sponsors/delete.asp, line 10


Can anyone help me?

Thanks in advance,

dvrslype

Comments

  • FlakesFlakes Member Posts: 642
    [b][red]This message was edited by Flakes at 2004-8-19 4:44:56[/red][/b][hr]
    : Hello,
    :
    : When I try to delete a record from my database, i get an error. I really don't get wat's wrong with this:
    :
    : [code]<%
    : Name = Request.Querystring("Name")
    : 'Database connection
    : Set DataConn = Server.CreateObject("ADODB.Connection")
    : DataConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("data.mdb")
    : Set rs = Server.CreateObject("ADODB.Recordset")
    : rs.ActiveConnection = DataConn
    : rs.CursorType = adOpenKeyset
    :
    : [b][red]rs.open = "delete * from Sponsors where Name = " & Name[/red][/b]
    :
    : response.redirect("Sponsors.asp")
    : %>[/code]
    :
    : The debug info i get from IIS is this:
    :
    : Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
    : [Microsoft][ODBC Microsoft Access-driver] Not enough parameters. The expected number is: 1.
    : /BD/sponsors/delete.asp, line 10
    :
    :
    : Can anyone help me?
    :
    : Thanks in advance,
    :
    : dvrslype
    :

    the error is beacause you haven't specified the connection to use with the opening of recordset the syntax is:
    rs.open sql,connection.

    But in this case,you don't even need a recordset.recordsets are used to retrieve data.

    Just do:
    [code]
    Name = Request.Querystring("Name")
    'Database connection
    Set DataConn = Server.CreateObject("ADODB.Connection")
    DataConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("data.mdb")

    DataConn.Execute "delete * from Sponsors where Name = '" & Name &"'"
    [/code]



Sign In or Register to comment.