| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 <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"> <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. |
|
#2
|
||||
|
||||
|
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
|
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > problems with adding info to an MS Access Database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|