Print Page | Close Window

Adding data to different cats. in a DB

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=8028
Printed Date: 01 April 2026 at 1:12am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Adding data to different cats. in a DB
Posted By: worldwide1504
Subject: Adding data to different cats. in a DB
Date Posted: 12 December 2003 at 7:50am

Hi.

I followed the Guestbook tutorial from this site, but instead of using it as a guestbook I made it a picture gallery.

I can succesfully add, edit, and delete pics after logging in.

But it only adds them to a certain category in the DB. And I have about 4 or 5 categories.

 

So the question is, when I add an image through the form...How can I make a drop down box that picks that category the pictures goes under?




Replies:
Posted By: aalavar
Date Posted: 12 December 2003 at 10:25am

Are the categories stored in the database, or do you just want to manually create a list of categories using HTML to insert into the database?  Also, if you can post the db fields in the table that holds the category I will try to help.



Posted By: worldwide1504
Date Posted: 12 December 2003 at 10:33am

I just had the categories as seperate tables:

game, music, other, tvmovies.

And there are images in each on. And I want to have drop down box that picks what image goes in what table/category.

 

Could I do something with booleans? So when someone picks a categroy from the drop down it sets it to true. And then on the next update page it says something like:

if blnGameCategory=true then
    add to game category
else if ...

Would that work?

 



Posted By: aalavar
Date Posted: 12 December 2003 at 10:55am

Add this to your form to add the drop down box:

<select name=catgy>
<option value="GAME">Game</option>
<option value="MUSIC">Music</option>
<option value="OTHER">Other</option>
<option value="TVMOVIES">TV Movies</option>
</select>

In the update page you can use a case statement to determine your table

category = Request("catgy")
case select category
 case "GAME"
  strSQL="select * from game"
 case "MUSIC"
  strSQL="select * from music"
 case "OTHER"
  strSQL="select * from other"
 case "TVMOVIES"
  strSQL="select * from tvmovies"
end select

The rest of the code shouldn't be changed...



Posted By: worldwide1504
Date Posted: 12 December 2003 at 11:29am

Ok, it says that there is a:

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

on this line

rsAddIcon.Open strSQL, adoCon



Posted By: aalavar
Date Posted: 12 December 2003 at 11:43am

Do this before the open statement:

Response.write strSQL

it should display the sql statement you are trying to perform.  Also, post the whole code before that point and I'll see if I can figure it out.  Or you can e-mail me both files (aalavar@bellsouth.net), I will see what the problem is. 



Posted By: worldwide1504
Date Posted: 12 December 2003 at 12:16pm

That Response.Write doesnt seem to do anything thing...but here is the code:

 


<%
'If the session variable is False or does not exsist then redirect the user to the unauthorised user page
If Session("blnIsUserGood") = False or IsNull(Session("blnIsUserGood")) = True then
 'Redirect to unathorised user page
 Response.Redirect"../default.asp"
End If
%>

<%
'Dimension variables
Dim adoCon               'Holds the Database Connection Object
Dim rsAddIcon        &nb sp;  'Holds the recordset for the new record to be added
Dim strSQL               'Holds the SQL query to query the database

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../db/Icons.mdb")

'Create an ADO recordset object
Set rsAddIcon = Server.CreateObject("ADODB.Recordset")

select case category
 case "GAME"
  strSQL = "SELECT game.url, game.name FROM game;"
 case "MUSIC"
  strSQL = "SELECT music.url, music.name FROM music;"
 case "OTHER"
  strSQL = "SELECT other.url, other.name FROM other;"
 case "TVMOVIES"
  strSQL = "SELECT tvmovie.url, tvmovie.name FROM tvmovies;"
end select

'Set the cursor type we are using so we can navigate through the recordset
rsAddIcon.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsAddIcon.LockType = 3

'Open the recordset with the SQL query
rsAddIcon.Open strSQL, adoCon




Posted By: aalavar
Date Posted: 12 December 2003 at 12:56pm

before your "Select case category" you need to request it... Add this line:

category = Request("catgy")

Where catgy was the name of the drop down box (if you copied and pasted mine, that was the name I used).



Posted By: worldwide1504
Date Posted: 13 December 2003 at 8:25am
Sweet it worked. Thanks a lot!


Posted By: worldwide1504
Date Posted: 13 December 2003 at 9:58am

 

Ok I have another question. Now I added the drop down box to the delete page.

So when i select a category, it takes me to the correct page to delete an icon. But when I click on one it takes me to an error page that says "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. "

Here is the code for that page:


<% 'Dimension variables
Dim adoCon            'Holds the Database Connection Object
Dim rsDeleteIcon   'Holds the recordset for the record to be deleted
Dim strSQL             'Holds the SQL query to query the database
Dim lngRecordNo     'Holds the record number to be deleted 
Dim lngCatName

'Read in the record number to be deleted
lngRecordNo = CLng(Request.QueryString("ID"))

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../db/Icons.mdb")

'Create an ADO recordset object
Set rsDeleteIcon = Server.CreateObject("ADODB.Recordset")

category = Request("category")

select case category
 case "GAME"
  strSQL = "SELECT game.* FROM game WHERE ID=" & lngRecordNo
 case "MUSIC"
  strSQL = "SELECT music.* FROM music WHERE ID=" & lngRecordNo
 case "OTHER"
  strSQL = "SELECT other.* FROM other WHERE ID=" & lngRecordNo
 case "TVMOVIES"
  strSQL = "SELECT tvmovie.* FROM tvmovie WHERE ID=" & lngRecordNo
end select

'Set the lock type so that the record is locked by ADO when it is deleted
rsDeleteIcon.LockType = 3

'Open the recordset with the SQL query
rsDeleteIcon.Open strSQL, adoCon

'Delete the record from the database
rsDeleteIcon.Delete

'Reset server objects
rsDeleteIcon.Close
Set rsDeleteIcon = Nothing
Set adoCon = Nothing

'Return to the delete select page in case another record needs deleting
Response.Redirect "delete_pick_cat_form.asp"
%>

And the error is apparently on this line:


'Open the recordset with the SQL query
rsDeleteIcon.Open strSQL, adoCon



Posted By: TYSON
Date Posted: 13 December 2003 at 7:44pm

Are you passing the category along with the ID in the querystring?

IE : Delete.asp?ID=1&category=MUSIC



-------------
http://www.fuo-motorsports.com/ - http://www.fuo-motorsports.com/


Posted By: worldwide1504
Date Posted: 14 December 2003 at 7:25am

No, but Ill try that later.

I gotta go to work now.



Posted By: worldwide1504
Date Posted: 14 December 2003 at 3:29pm

Ok, now I get this error:

 Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.

On this line:


'Open the recordset with the SQL query
rsDeleteIcon.Open strSQL, adoCon



Posted By: aalavar
Date Posted: 15 December 2003 at 6:36am
On the delete page, what did you name the drop down box?  What does your whole querystring look like?  i.e. copy and paste everything in the url after the ?, that may help to find it.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net