| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Small sql database query problem
i am new to asp and have been going grand till i hit this little snag.
I am attempting to query the database to return the entry in the database with Manufacture_Name equals to a value passed into this page by a form in the previous page. This wont work for me. However it will work for me when i pass in the vlue of the Manufacture_Code of the same entry in the database. i am only making a small error betwwen the different syntax of numbers and letters. Any help would be very appreciated. here is my code 'Dimension variables Dim WordID 'Array to hold the ID number for each comment to be deleted 'Set the Lock Type for the records so that the record set is only locked when it is deleted rsCommon.LockType = 3 'Run through till all checked bad words are deleted iaryBadWordID = Request.Form("m_code") 'Initalise the strSQL variable with an SQL statement to query the database 'strSQL = "SELECT " & strDbTable & "Manufacture.* FROM " & strDbTable & "Manufacture ORDER BY " & strDbTable & "Manufacture.Manufacture_Code ASC;" strSQL = "SELECT " & strDbTable & "Manufacture.* FROM " & strDbTable & "Manufacture" strSQL = strSQL & " WHERE Manufacture_Name =" & ('iaryBadWordID') 'Query the database rsCommon.Open strSQL, adoCon But it does work when i change the value passed in from the previous form, to be the Manufacture_Code That code is identical only for this line strSQL = "SELECT " & strDbTable & "Manufacture.* FROM " & strDbTable & "Manufacture" strSQL = strSQL & " WHERE Manufacture_Code =" & ('iaryBadWordID') So i'm guessing its on this line i have the problem. |
|
#2
|
||||
|
||||
|
Do a Response.write on your sql statement do see what is being passed to the database.
|
|
#3
|
|||
|
|||
|
the database isn't being connected to. As in, the SELECT .... FROM.... WHERE statementis leaving me with nothing for Manufacture_Name. The statement isn't executing due to an error. Perhaps the line
strSQL = "SELECT " & strDbTable & "Manufacture.* FROM " & strDbTable & "Manufacture" strSQL = strSQL & " WHERE Manufacture_Name =" & ('iaryBadWordID') should be something like strSQL = "SELECT " & strDbTable & "Manufacture.* FROM " & strDbTable & "Manufacture" strSQL = strSQL & " WHERE Manufacture_Name =" "'" & ('iaryBadWordID') "'" seeing as i'm dealing with text. and not numbers |
|
#4
|
||||
|
||||
|
Like I said, do a response.write on the sql statement and post what it displays in the browser.
|
|
#5
|
|||
|
|||
|
could you write out how the statement would look. i'm new to this. thanks for your help
|
|
#6
|
||||
|
||||
|
Code:
strSQL = "SELECT " & strDbTable & "Manufacture.* FROM " & strDbTable & "Manufacture"
strSQL = strSQL & " WHERE Manufacture_Name =" & ('iaryBadWordID')
Response.write(strSQL)
Response.end
|
|
#7
|
|||
|
|||
|
This is what i got:
SELECT tblGBManufacture.* FROM tblGBManufacture WHERE Manufacture_Name =Acme Acme is correct. These are the current entries in my Manufacture Database Manufacture CodeManufacture NameContact NameAddress 1Address 2CityCountyPost CodeCountryPhone NumberFax NumberE-mail AddressWeb AddressModified By852 ihgjk uju uuygu uyv u vu vu v 123 125 vgo uiy 8526 tool frank main town main street cligo sligo p4k4 irl 45674 87 ppjpij pijopijoi 963 Acme John dub dub dub dyg (the bit missing was just my copying and pasting) What i am trying to do with this code is pass in the manufacture name but store the manufactures code. As i said earlier i can pass in the manufacturer code and save its name. this is my more complete code. <% Option Explicit %> <!--#include file="common.asp" --> <% 'Set the response buffer to true as we maybe redirecting Response.Buffer = True 'Dimension variables Dim iaryBadWordID 'Array to hold the ID number for each comment to be deleted 'Set the Lock Type for the records so that the record set is only locked when it is deleted rsCommon.LockType = 3 'Run through till all checked bad words are deleted iaryBadWordID = Request.Form("Manufacture_Code") 'Initalise the strSQL variable with an SQL statement to query the database strSQL = "SELECT " & strDbTable & "Manufacture.* FROM " & strDbTable & "Manufacture" strSQL = strSQL & " WHERE Manufacture_Name =" & (iaryBadWordID) Response.write(strSQL) Response.end 'Query the database rsCommon.Open strSQL, adoCon Dim mcode mcode = rsCommon("Manufacture_Code") <------ this is were i am trying to obtain the manufacture_code i want to save. i save it below 'Reset Server Variables rsCommon.Close 'Set rsCommon = Nothing 'adoCon.Close 'Set adoCon = Nothing %> <% 'Set the response buffer to true as we maybe redirecting Response.Buffer = True 'Dimension variables Dim intBadWord 'Loop counter for the bad words 'Set the Lock Type for the records so that the record set is only locked when it is deleted rsCommon.LockType = 3 'Initalise the strSQL variable with the SQL string strSQL = "SELECT " & strDbTable & "Component.* FROM " & strDbTable & "Component;" 'Query the database rsCommon.Open strSQL, adoCon 'Tell the recordset we are adding a new record rsCommon.AddNew 'Add new records to fields rsCommon.Fields("Component_Code") = Request.Form("Component_Code") rsCommon.Fields("Name") = Request.Form("Name") rsCommon.Fields("Location") = Request.Form("Location") rsCommon.Fields("Manufacture_Code") = mcode 'rsCommon.Fields("Modify_By") = Request.Form("Component_Code") rsCommon.Fields("Modify_By") = application("modify") 'save the recordset back to the database rsCommon.Update 'Reset Server Variables rsCommon.Close Set rsCommon = Nothing adoCon.Close Set adoCon = Nothing 'Return to the bad word admin page Response.Redirect "components.asp" %> |
|
#8
|
||||
|
||||
|
should be like this
Code:
...WHERE Manufacture_Name = '" & iaryBadWordID & "'" |
|
#9
|
|||
|
|||
|
I'm just after seeing your last post. Thanks very much for your help. That worked perfectly
|
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Small sql database query problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|