Can someone please check this out

Results 1 to 2 of 2

Thread: Can someone please check this out

  1. #1
    Join Date
    Dec 1969

    Default Can someone please check this out

    &nbsp;<BR> I am trying to loop through the values of a form which contain data from the database, each row of data contains the same form element names i.e. 20 FirstName records = 20 form elements with the name of FirstName, and so on.<BR><BR>What I am trying to do is loop through the values in the form and construct a SQL update statement, but when the form processes, it gives me a return of false, with out ever processing the sql construction part of the code. Can you look at this code and see if you see an error that could cause this please. <BR><BR>For ix = 1 to Request.Form.Count<BR> <BR> fieldName = Request.Form.Key(ix)<BR> fieldValue = Request.Form.Item(ix) <BR> <BR> sqlStmt ="Update NonDealRevenues Set" & FieldName = FieldValue & " Where ID="&Request("ID")(ix)<BR> Response.Write SQLStmt<BR> Response.End<BR>next <BR><BR>thanks, <BR> mj

  2. #2
    Join Date
    Dec 1969

    Default Did you *USE* the debug output you got???

    Did you look at what the line Response.Write SQLStmt gave you???<BR><BR>I betcha it gave you this:<BR>&nbsp; &nbsp; Update NonDealRevenues Set False Where ID=1732<BR>(well, the ID value is made up).<BR><BR>Yes? Now, WHY would you get the value False in there instead of what you asked for?<BR><BR>Because the *EXPRESSION* <BR>&nbsp; &nbsp; FieldName = FieldValue<BR>is almost surely false. And you asked VBS to EVALUATE THAT EXPRESSION, didn&#039;t you?<BR><BR>If you want the = sign to be part of the SQL, then you have to put it in quotes!!!<BR><BR>sqlStmt = "Update NonDealRevenues Set " & FieldName & "=" & FieldValue & " Where ID="&Request("ID")(ix)<BR><BR>Note that you also need a space after the word Set. And of course this only works if the field named by FieldName is a NUMERIC field! If it is a text field, you need &#039;...&#039; around the value.<BR><BR>There are other bugs in here.<BR><BR>Your For ix statement is processing *ALL* the form fields, yes? And yet you are apparently relying on Request("ID") to be an array of values, too? Then how can you involve it in the FOR IX loop???<BR><BR>And how do you know that the array of "ID" values will correspond to the FOR IX values????<BR><BR>Looks to me like this needs more work to get it functional.<BR><BR><BR>

Posting Permissions

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