Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 9th, 2004, 11:53 AM
bigjay bigjay is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 bigjay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
problems with adding info to an MS Access Database

I am currently writing a new technical website for the staff at the office I work at. The site is run off an MS Access database for the information it stores. The information is stored based on category and subject so it is easier for quick viewing. The problem I have is when a user is to add a new subject to the database the code will store the ID of the category that it is to be located under but will not store the actual subject that is entered into the text box. Here is what the code looks like with certain tags removed:


<BODY bgColor=darkgray>
<P align=center><STRONG>Add a Subject to a Category Field&nbsp;<br><br>

Dim strSQL
Dim cnnCrapDB
Dim rstCategory, rstSubject
Dim iRequestedID
dim strDBPath

strDBPath = Server.MapPath("crap.mdb")
iRequestedID = Trim(Request.QueryString("id"))
iRequestedID = Replace(iRequestedID, "'", "''")
If IsNumeric(iRequestedID) Then
iRequestedID = CInt(iRequestedID)
Else
iRequestedID = 0
End If
<form action="subjadd.asp" method="post" id=form2 name=form2>
Set cnnCrapDB = Server.CreateObject("ADODB.Connection")
cnnCrapDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
strSQL = "SELECT * FROM category;"
Set rstCategory = Server.CreateObject("ADODB.Recordset")
rstCategory.Open strSQL, cnnCrapDB, 0, 3, &H0001
If Not rstCategory.EOF Then
rstCategory.MoveFirst
%>
<select name="id" onChange=document.location.href=form[0].value>
<option></option>
<%
Do While Not rstCategory.EOF
Response.Write "<option value=""subjadd.asp?id="
Response.Write rstCategory.Fields("catid")
Response.Write """"
If rstCategory.Fields("catid") = CInt(iRequestedID) Then
Response.Write "selected=""true"""
End If
Response.Write ">"
Response.Write Trim(rstCategory.Fields("description"))
Response.Write "</option>" & vbCrLf
rstCategory.MoveNext
Loop
%>
</select>
<%
End If
rstCategory.Close
Set rstCategory = Nothing
<input type="text" style="WIDTH: 120px" name="subadd">&nbsp;
<INPUT type=submit value=Submit id=submit1 name=submit1>
If iRequestedID <> 0 Then
strSQL = "SELECT * FROM subject;"
Set rstSubject = Server.CreateObject("ADODB.Recordset")
rstSubject.Open strSQL, cnnCrapDB, 1, 2, 1 'adOpenKeyset, adLockPessimistic, adCmdText
rstSubject.AddNew
subadd = Request.Form("subadd")
rstSubject.Fields("description") = Request.QueryString("subadd")
rstSubject.Fields("catid") = Request.QueryString("id")
rstSubject.Update
rstSubject.Close
Set rstSubject = Nothing

End If

cnnCrapDB.Close
Set cnnCrapDB = Nothing

</form>


Any help in this will be greatly appreciated. If I use the code like this the dropdown will give me my choices and I will choose an option and if I type in text into the text box and hit submit, the subject table in the database will update itself with a new id, the id of the category that was selected but the description box will be blank even though I have typed something into the text box that points to that description box.

Reply With Quote
  #2  
Old September 9th, 2004, 01:07 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 7 h 4 m 46 sec
Reputation Power: 469
If you have both a value and text in a dropdownlist, then when the dropdown object is requested, the value is taken, not the text.

Just remove the value from the dropdown object and it will capture the text instead.

Like this
Code:
Do While Not rstCategory.EOF
   If rstCategory("catid") = CInt(iRequestedID) Then
      selected = " selected"
   Else
      selected = ""
   End If

   Response.write("<option " & selected & ">" & Trim(rstCategory("description")) & "</option>")

   rstCategory.MoveNext
Loop

Reply With Quote
  #3  
Old September 9th, 2004, 01:37 PM
bigjay bigjay is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 bigjay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you for the info. IN the program there are two separate pieces. One piece is the dropdown list that pulls the category table from the database and shows the name but not the id but pulls the id and puts in memory. Then there is a text box that is left open for you to write your own text and that is supposed to be set to add to the description field. The dropdown shows the text so that the user can see what category they are choosing, not just the id.


I hope I didn't misunderstand what you were saying

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > problems with adding info to an MS Access Database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT