|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using ASP to delete records on access 2000
Hey guys, could you possibly take a look at the following code and let me know whats going wrong with it? When I run the code (its part 2 of 2 screens, where part 1 is a form) it says that there is an error on line 32 (adoCmd.execute). I cant work out whats going wrong, coz everything else seems to work fine.
Please help, and thanks in advance for your time. Chris Code as follows: <% @language="vbscript" %> <% Option Explicit %> <% Response.Buffer=True %> <html> <head> <title>Popup deleted</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <h1> Popup Deleted </h1> <!-- #include file="dbConn.asp" --> <!-- #include file="adovbs.inc" --> <% Dim adoConn, adoCmd, strSQL, pid ' Get the values posted from the Form pid = Request("pid") Set adoConn = Server.CreateObject("ADODB.Connection") Set adoCmd = Server.CreateObject("ADODB.Command") adoConn.Open strConnection strSQL = "DELETE FROM POPUP WHERE PID = '" & pid & "'" ' Set up the Command object adoCmd.CommandText = strSQL adoCmd.CommandType = adCmdText adoCmd.ActiveConnection = adoConn ' Execute the SQL on the Command object adoCmd.Execute ' Tidy up Set adoCmd = Nothing adoConn.Close Set adoConn = Nothing %> <br> <p> <a href="PSA_Index.htm">Start Over </a> </body> </html> |
|
#2
|
|||
|
|||
|
Ok, I'll make your life and code easier
![]() Why oh why are you creating a Command Object ? Command Object's are often used for SPROCs(Store Procedures) with output parameters and what not... *All* you have is a simple DELETE query. Don't create the extra overhead of the Command Object Simply use the/your Connection object Also note, that since your using/creating a DELETE query then NO RECORDSET are necessary So...try this: <% Const adExecuteNoRecords = 128 Dim adoConn Dim strSQL Dim pid ' Get the values posted from the Form pid = Request("pid") strSQL = "DELETE FROM POPUP WHERE PID = '" & pid & "'" 'FOR DEBUG ONLY 'Response.Write strSQL & "<hr>" 'Response.End Set adoConn = Server.CreateObject("ADODB.Connection") adoConn.Open strConnection adoConn.execute strSQL, adExecuteNoRecords adoConn.Close Set adoConn = Nothing %> That's it...simple, effecient, fast and clean Now all you need to do is set the *strConnection* variable and also make sure the PID field isn't numeric otherwise you'll have to *change* your DELETE query to: strSQL = "DELETE FROM POPUP WHERE PID = " & CLng(pid) You could also make a validation of the variable *pid* to make sure that there is a value in it, otherwise the SQL Query might crash...for example if *pid* is equal to the letter "A" when in fact it is expecting a number...or if it holds an apostrophe...or...or... Hope this helps! Sincerely Vlince |
|
#3
|
|||
|
|||
|
Wow thanks for such a prompt reply.
|
|
#4
|
|||
|
|||
|
Eeek, im quick to return with bad news.
I've tried to use the code that you supplied, and I still get an error message. I have previously specified what strConnection is through my adoConn.asp include file. The error message I get this time, again is on line 32 (adoConn.Open strConnection) and says: Microsoft JET Database Engine (0x80040E07) Data type mismatch in criteria expression. /psa/delete_pm_conf.asp, line 32 the value of 'pid' is going to be a numeric (its an id number in the database), but trying both values ' & pid &' and & CLng(pid) dont work. Any other suggestions? |
|
#5
|
|||
|
|||
|
Well if line 32 is the adoConn.Open strConnection
Then your error is in your strConnection variable Try and see if the *string* inside the variable is correct! Vlince |
|
#6
|
|||
|
|||
|
Ok feel free to start slapping me with fish any time (you'll have to be patient, only been doing this for 2 days or so - everything that university taught me seems to be horse sh!t and doesnt work), but...
..with a bit of tweaking, i've got it thus far: Error Type: Microsoft JET Database Engine (0x80040E07) Data type mismatch in criteria expression. /psa/delete_pm_conf.asp, line 31 Code as you gave earlier: Set adoConn = Server.CreateObject("ADODB.Connection") adoConn.Open strConnection adoConn.execute strSQL, adExecuteNoRecords <--**Line 31** adoConn.Close Set adoConn = Nothing the connection string (strConnection) is defined in dbConn.asp as: <% Dim strDBVirtualPath, strDBLocation, strConnection strDBVirtualPath = "PSA.mdb" strDBLocation = Server.Mappath(strDBVirtualPath) strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBLocation Response.Write Chr(13) %> Im not very good at this milarky - im meant to be a writer, not a programmer ![]() Chris |
|
#7
|
|||
|
|||
|
Ok, I'll try and go easy on you since it's friday
![]() Now... Let's forget about the include files you have. In fact I'd like you to create a simple *NEW* asp page. Call it whatever you want... then inside that page write this: <%@ Language=VBScript %> <% Const adExecuteNoRecords = 128 Dim lngPin Dim strSql Dim oConn lngPin = Trim(Request("pid")) 'FOR DEBUG ONLY 'Response.Write "-->" & lngPin & "<--<hr>" 'Response.End 'Validation of the *lngPin* variable If lngPin = "" Then Response.Write "No did not provide a pin number..." Response.End End If 'Let's validate if the *lngPin* is a numeric value If NOT IsNumeric(lngPin) Then Response.Write "The pin number must be a number..." Response.End End If 'Now let's create the SQL Query 'NOTICE that I didn't connect to my database yet... strSql = "DELETE FROM POPUP WHERE PID = " & CLng(lngPin) 'FOR DEBUG ONLY 'Response.Write strSql & "<hr>" 'Response.End 'Ok...we are now ready to connect to your database... Set oConn = Server.CreateObject("ADODB.Connection") oConn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _ "Dbq=c:\somepath\mydb.mdb;" & _ "Uid=admin;" & _ "Pwd=" 'Once the connection is open, let's execute your Query oConn.execute strSql, adExecuteNoRecords oConn.Close Set oConn = Nothing %> Now notice the first thing...I've prefixed the variable *lngPin* with lng because it tells *ME* the programmer to expect a number. since variables in VBScript aren't typed, prefixing them *will* help me understand what to expect in *that* variable. Also, you'll need to change the value in the oConn.Open to put your own... this is a link *YOU* must bookmark http://www.able-consulting.com/ADO_Conn.htm try that... Also, UNCOMMENT the lines under 'FOR DEBUG ONLY sections in order to see what goes on *BEFORE* you actually execute your SQL Query! Hope this helps! Sincerely Vlince |
|
#8
|
|||
|
|||
|
Cheers mate.
|
|
#9
|
|||
|
|||
|
This is what I do
Set connection = Server.CreateObject("ADODB.Connection") Set rsDelete = Server.CreateObject("ADODB.Recordset") dsn = "DSN=SampleDB2" *** I am using DSN for my database ****-* connection.Open dsn sql = strSQL = "DELETE FROM POPUP WHERE PID = '" & pid & "'" rsDelete .Open sql, connection Paul. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Using ASP to delete records on access 2000 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|