Too Few Parameters - Help!

Results 1 to 5 of 5

Thread: Too Few Parameters - Help!

  1. #1
    Tim Frick Guest

    Default Too Few Parameters - Help!

    I received the following error when trying to update a database made in Access.<BR><BR>Database Errors Occured<BR>UPDATE Addresses SET FirstName=&#039test&#039,LastName=Leverling where AddressID=3<BR><BR>Error #-2147217904<BR><BR>Error desc. -> [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.<BR><BR>======================<BR><BR>Here is the code from tableedit.asp. This posts the changed information to tableeditrespond.asp, which I have included below as well.<BR><BR>&#060;html><BR><BR>&#060;head><BR>&#0 60;title>tableedit.asp&#060;/title><BR>&#060;/head><BR><BR>&#060;body bgcolor="#FFFFFF"><BR>&#060;% <BR>&#039 My ASP program that given an AddressID, allows editing a record<BR><BR>myDSN="DSN=tables.dsn"<BR><BR>set conntemp=server.createobject("adodb.connection")<B R>conntemp.open myDSN<BR>form_ID=request.querystring("which")<BR>< BR>sqltemp="select * from Addresses "<BR>sqltemp=sqltemp & " where AddressID=" & form_id<BR><BR>set rstemp=conntemp.execute(sqltemp)<BR><BR><BR>form_a dID=rstemp("AddressID")<BR>form_firstname=rstemp(" FirstName")<BR>form_lastname=rstemp("LastName")<BR ><BR>rstemp.close<BR>set rstemp=nothing<BR>conntemp.close<BR>set conntemp=nothing<BR>&#037;&#062;<BR><BR>&#060;form name="Addresses" action="tableeditrespond.asp" method="POST"><BR> &#060;input type="hidden" name="id" value="&#060;%=form_adid&#037;&#062;">&#060;p>Addr ess ID: &#060;%=form_adid&#037;&#062;&#060;/p><BR> &#060;p>First Name: &#060;input type="TEXT" name="FirstName" value="&#060;%=form_firstname&#037;&#062;" size="20">&#060;/p><BR> &#060;p>Last Name: &#060;input type="TEXT" name="LastName" value="&#060;%=form_lastname&#037;&#062;" size="20">&#060;/p><BR> &#060;p>&#060;input type="SUBMIT"> &#060;/p><BR>&#060;/form><BR>&#060;/body><BR>&#060;/html><BR><BR>==========================<BR>tableed itrespond.asp<BR><BR>&#060;html><BR><BR>&#060;head ><BR>&#060;title>tableeditrespond.asp&#060;/title><BR>&#060;/head><BR><BR>&#060;body bgcolor="#FFFFFF"><BR>&#060;%<BR>on error resume next<BR>form_firstname=request.form("FirstName")<B R>form_lastname=request.form("LastName")<BR>form_I D=request.form("ID")<BR><BR>Set Conn = Server.CreateObject("ADODB.Connection")<BR>conn.op en "DSN=tables.dsn"<BR><BR>&#039 change apostrophe to double apostrophe<BR>form_firstname=Replace(form_firstnam e, "&#039", "&#039&#039") <BR><BR>SQLstmt = "UPDATE Addresses SET "<BR>SQLStmt = SQLstmt & "FirstName=&#039" & form_firstname & "&#039,"<BR>SQLstmt = SQLstmt & "LastName=" & form_lastname<BR>SQLStmt = SQLStmt & " where AddressID=" & form_id <BR><BR><BR>Set RS = Conn.Execute(SQLStmt)<BR><BR>If err.number>0 then<BR>response.write "VBScript Errors Occured:" & "&#060;P>"<BR>response.write "Error Number=" & err.number & "&#060;P>"<BR>response.write "Error Descr.=" & err.description & "&#060;P>"<BR>response.write "Help Context=" & err.helpcontext & "&#060;P>" <BR>response.write "Help Path=" & err.helppath & "&#060;P>"<BR>response.write "Native Error=" & err.nativeerror & "&#060;P>"<BR>response.write "Source=" & err.source & "&#060;P>"<BR>response.write "SQLState=" & err.sqlstate & "&#060;P>"<BR>end if<BR>IF conn.errors.count> 0 then<BR>response.write "Database Errors Occured" & "&#060;P>"<BR>response.write SQLstmt & "&#060;P>"<BR>for counter= 0 to conn.errors.count<BR>response.write "Error #" & conn.errors(counter).number & "&#060;P>"<BR>response.write "Error desc. -> " & conn.errors(counter).description & "&#060;P>"<BR>next<BR>else<BR>response.write "&#060;B>Everything Went Fine. Record is updated now!&#060;/b>"<BR>response.write "<BR>" & SQLstmt<BR>end if<BR><BR>rs.close<BR>set rs=nothing<BR>Conn.Close<BR>set conn=nothing<BR>&#037;&#062;<BR>&#060;/body><BR>&#060;/html><BR><BR>=======================<BR>If I add the following statement to tableeditrespond.asp<BR><BR>& "&#039,"<BR><BR>to the line LastName=" & form_lastname<BR>I can solve this error, only to get a syntax error.<BR><BR>I am using this from an example at learnasp.com.<BR><BR>This is probably a small error, but if you could help me out I would appreciate it!<BR><BR>Thanks,<BR>Tim Frick<BR>mutjf3@wiu.edu

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Too Few Parameters - Help!

    When you attempt to update or insert string or date variables, you need to use the single quotes. So, you have:<BR><BR>UPDATE Addresses SET FirstName=&#039test&#039,LastName=Leverling where AddressID=3<BR><BR>Well, you&#039ve got quotes around the value of FirstName (&#039test&#039), which is great, but you also need them around LastName&#039s value.<BR> Let&#039s look at your sql construction code:<BR><BR>SQLstmt = "UPDATE Addresses SET "<BR>SQLStmt = SQLstmt & "FirstName=&#039" & form_firstname & "&#039,"<BR>SQLstmt = SQLstmt & "LastName=" & form_lastname<BR>SQLStmt = SQLStmt & " where AddressID=" & form_id <BR><BR>You will need to edit the line:<BR>SQLstmt = SQLstmt & "LastName=" & form_lastname<BR><BR>so that it has the single quotes around form_lastname.<BR>SQLstmt = SQLstmt & "LastName=&#039" & form_lastname & "&#039"<BR><BR>(See, just like the way FirstName is contructed.) Happy Programming!<BR>

  3. #3
    N. Meneses Guest

    Default RE: Too Few Parameters - Help!

    Thanks for the help as well as I had missing single quotes in my query which were ****ing annoying. here is my working query for those using this style of syntax<BR><BR>sqltemp = "SELECT * FROM Students WHERE students.surname = &#039"& strsurname & "&#039 AND students.forename = &#039"& strforename&"&#039 "<BR><BR>set rstemp=conntemp.execute(sqltemp) <BR><BR>Very happy programming - Now!<BR>

  4. #4
    j Illson Guest

    Default RE: Too Few Parameters - Help!

    Saw your response above and have a similar problem. I know little about asp, just started looking at it. The following code was generated by the MS Access97 wizard. Trying to get the form it generated to accept an entry without the single quotes. Was considering doing some javascript to add the single quotes when form was submitted but your response seems a much better way. Been trying to implement what you did, but no luck. Can you (or anyone) help with this?<BR><BR>This is the form:<BR><BR>&#060;FORM METHOD="GET" ACTION="Query1_1.ASP"><BR>Name &#060;INPUT TYPE="Text" NAME=[Name]>&#060;P><BR>&#060;INPUT TYPE="Submit" VALUE="Run Query"><BR><BR>Which sends it to another page with a table:<BR><BR>&#060;%<BR>Param = Request.QueryString("Param")<BR>Data = Request.QueryString("Data")<BR>&#037;&#062;<BR>&#0 60;%<BR>If IsObject(Session("TestAccess_conn")) Then<BR> Set conn = Session("TestAccess_conn")<BR>Else<BR> Set conn = Server.CreateObject("ADODB.Connection")<BR> conn.open "TestAccess","",""<BR> Set Session("TestAccess_conn") = conn<BR>End If<BR>&#037;&#062;<BR>&#060;%<BR> sql = "SELECT Drivers.LastName, Drivers.FirstName, Drivers.DateOfBirth, Drivers.Comments FROM Drivers WHERE (((Drivers.LastName)=" & Request.QueryString("[Name]") & ")) "<BR> If cstr(Param) &#060;> "" And cstr(Data) &#060;> "" Then<BR> sql = sql & " And [" & cstr(Param) & "] = " & cstr(Data)<BR> End If<BR> Set rs = Server.CreateObject("ADODB.Recordset")<BR> rs.Open sql, conn, 3, 3<BR>&#037;&#062;<BR><BR>Any help would be appreciated.<BR>Thanks.


  5. #5
    j IIlson Guest

    Default RE: Too Few Parameters - Help!

    Work it out like this. Wrote this javascript validation on form that strips out all single quotes (&#039)(god **** you, O&#039bryan) replaces them with two single quotes (&#039&#039), then places single quotes on each end. It does this in a &#039hidden&#039 text box so user is unaware of all this.<BR><BR>&#060;script language="JavaScript"><BR>&#060;!--<BR>function test(formnumber) {<BR>// formnumber is form location in DOM as per &#039onSubmit="return test(0)&#039<BR>var strText1 = document.forms[formnumber].elements[0].value<BR>var regexp = /&#039/g<BR>if (strText1 == ""){<BR>alert("You Must Enter A Name")<BR>return false }<BR>else {<BR>strText1 = strText1.replace(regexp, "&#039&#039")<BR>document.forms[formnumber].elements[1].value = "&#039" + strText1 + "&#039"<BR>return true<BR>}}<BR>//--><BR>&#060;/script><BR><BR>The form elements look like this:<BR><BR>&#060;input id="Name1a" type="Text"><BR>&#060;input id="Name2a" type="hidden" name="[Enter First And Last Name1]"><BR><BR>Works OK, but would still like to know how to do it with asp.<BR>Any suggestions?<BR>Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •