 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 14th, 2004, 01:45 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I am not sure I understand the question. What do you mean with
Quote:
|
quote:how can i empty the size1 field other condition
|
Are you trying to insert NULL in the field?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

June 14th, 2004, 02:12 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yea but note it field has value like 5 5.5 in txt format
i want to save value when check box is on or other wise empty
field when cheked box is off pls help me
|
|

June 14th, 2004, 02:29 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You can insert NULL (if your database column allows that).
strsql = "UPDATE tblRings SET name = '" & ringname & "', [desc] = '" & desc
If Request("s1")= "on" Then
strsql = strsql & ", size1 = 5.5"
Else
strsql = strsql & ", size1 = null"
End If
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

June 14th, 2004, 05:05 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
gr8 now its all fine thanks imar
|
|

February 22nd, 2007, 10:21 AM
|
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi everyone, this is my first post. :D
I have an admin page that allows a manager to log in and delete products from his available prod list depending on inventory. I have it set up where a SQL statement and some asp print to the screen all of the products in a table. Next to each prod in the list is a checkbox. The checked boxes are the prods to be deleted. The form, on action send to another file which handles with request.form.
I use a loop and basically concatenate all items from the form into a long DELETE sql statement which ultimately looks like this which I just printed to screen, but doesn't work with objcon:
DELETE FROM prod WHERE listnum = 2 AND WHERE listnum = 3 AND WHERE listnum = 6 AND WHERE listnum = 8 AND WHERE listnum = 10
this isn't working for me and I get an error each time,
which looks like this:
Syntax error (missing operator) in query expression 'listnum = 3 AND WHERE listnum = 4 AND WHERE listnum = 6 AND WHERE listnum = 7'
My SQL skills are pretty bad. But any help would be GREATLY appreciated. Thank you very much!
Here is the code for you to look at:
<%@ Language=VBscript %>
<% Option Explicit%>
<% Response.Buffer = true %>
<%
dim counter
counter=1
dim del(100)
dim x
dim strSQL
dim del_list
dim add
strSQL = "DELETE FROM prod WHERE listnum = " & request.Form("listnum")(counter)
del_list = ""
dim upper
upper=request.Form("listnum").count
dim rs
if upper > 1 then
For counter = 2 To Request.Form("listnum").Count
del_list = del_list & " AND WHERE listnum = " & Request.Form("listnum")(counter) &""
Next
end if
strSQL = strSQL&del_list
set rs = server.CreateObject("ADODB.Recordset")
rs.Open strSQL, objConn
%>
|
|

February 22nd, 2007, 10:28 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
A SQL statement can contain only one WHERE statement (void of subqueries that is) anyway, your DELETE statement could look like this:
DELETE FROM prod WHERE listnum = 2 AND listnum = 3 AND listnum = 6 AND listnum = 8 AND listnum = 10
or this (more readable)
DELETE FROM prod WHERE listnum IN(2,3,6,8,10)
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
|
|

February 22nd, 2007, 11:13 AM
|
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thank you for such a speedy response!
I used the "IN" method and it creates a much nicer SQL statement. However, I'm getting another error:
Could not delete from specified tables.
I think the error originates from how I have the database set up. The DB has 2 columns. 1 column is called "listnum", is a unique number value and is the KEY. The other column is called "product" and is a list of each product my company sells, is text.
I want to delete these products from the database when the manager checks a check box and hits send. I'm trying to delete the entire row, based on the unique "listnumber".
Is this a legitimate thing to try?
Here is the code from the form page with the checkbox:
<%@ Language=VBscript %>
<% Option Explicit%>
<% Response.Buffer = true %>
<%
dim rs
dim prod(100)
dim listnum(100)
dim strSQL
dim c
c=1
set rs = server.CreateObject("ADODB.Recordset")
strSql = "SELECT * FROM prod"
rs.Open strSql, objConn
while not rs.eof
prod(c) = rs("product")
listnum(c) = rs("listnum")
rs.movenext
c = c+1
wend
%>
<html>
<head>
<title>Mil International - Administrator Only</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table cellpadding="3" cellspacing="3" border="1" align="center">
<tr>
<td colspan="3">Mil International Products List</td>
</tr>
<tr>
<td></td><td>List #</td><td>Product Name</td>
</tr>
<% dim i
c = c-1
%>
<form action="delete-handler.asp" method="post">
<%for i = 1 to c %>
<tr>
<td><INPUT TYPE=CHECKBOX NAME="listnum" value="<%=listnum(i)%>"></td><td></td><td><% response.write(prod(i)) %> </td>
</tr>
<% Next %>
<input type="submit" name="submit" value="Send">
</form>
</table>
</body>
</html>
Here is the SQL again:
<%
dim counter
counter=1
dim del(100)
dim x
dim strSQL
dim del_list
dim add
strSQL = "DELETE FROM prod WHERE listnum IN ("
del_list = ""
dim upper
upper=request.Form("listnum").count
dim rs
if upper >+ 1 then
For counter = 1 To Request.Form("listnum").Count-1
del_list = del_list & Request.Form("listnum")(counter) & "," &""
Next
del_list=del_list+Request.Form("listnum")(counter)
end if
strSQL = strSQL&del_list&")"
set rs = server.CreateObject("ADODB.Recordset")
rs.Open strSQL, objConn
%>
Thank you VERY VERY much, I would be spending hours trying to debug this myself. I greatly appreciate your help.
-Brian
|
|

February 22nd, 2007, 11:31 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Ok, let me try to explain this. Your table that contains the products and the key field listnum, do you have any other tables in your database that have a foriegn key that relates back to the listnum column in your products table?
What i mean is
Table1 Products
listnum desc
1 widgetA
2 widgetB
Table2 somethign
pk listNum_fk desc
1 2 something
2 1 something
Given that, Table2 relates back to table1 based on the listNum column but, if you try to delete a row out of Table1 you will get an error similiar to "Foriegn Key contraint on field listNum_fk in table table2 DELETE Fails"
I suspect this may be the problem you are having.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
|
|

February 22nd, 2007, 11:53 AM
|
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi, thanks again for being so speedy.
[u]In response to the foreign key constraint</u>:
No, this is a very simple database system. 1 DB, with 1 table, that has 2 rows. I'm sorry for any confusion.
I've noticed that if I continually hit F5 to refresh the page, the error moves from what seems to be a SQL error to a problem with my DBCONN include file.
dbconn.inc =
<%
dim objConn, strConn, sqlString
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.Mode=3
strConn= "filedsn=" & Server.MapPath("milinternational.dsn")
strConn=strConn & ";DBQ=" & Server.MapPath("milinternational.mdb")
objConn.Open strConn
%>
Here is the error I am getting:
Unspecified error
/milin/dbconn.INC, line 7
I hope this helps.
|
|
 |