472,142 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

Update Multiple Posts At same time

Hello there i wonder how the update string should look if i want to update multiple posts at same time.

Iam looping out all post from a table like this:
Expand|Select|Wrap|Line Numbers
  1.     set recsettraktamente = objconn.execute("select * from lander_belopp")
  2.  
  3.     if recsettraktamente.eof then
  4.     response.write "Finns inga traktament belopp angivna"
  5.  
  6.     else
  7.  
  8.     response.write "<form action=""?do=spara_traktamente"" method=""post"">"
  9.  
  10.     do until recsettraktamente.eof
  11.     response.write ""&recsettraktamente("land")&" <input type=""text"" size=""5"" name=""belopp"" value="""&recsettraktamente("belopp")&""">"
  12.  
  13.     bytrad = bytrad+1
  14.     if bytrad = 1 then
  15.     response.write "<br/>"
  16.     bytrad = 0
  17.     end if
  18.  
  19.     recsettraktamente.movenext
  20.     loop
  21.     response.write "<div style=""float:right""><input type=""submit"" value=""Spara Ändringar""></div>"
  22.     response.write "</form>"
  23.     recsettraktamente.close : Set recsettraktamente = Nothing
  24. end if
  25.  
Havent written the Update string because i dont know how i should look like. i tried whit something like this before, but get "index out of range"

Expand|Select|Wrap|Line Numbers
  1. dim i
  2. if request.querystring("do") = "spara_traktamente" then
  3.   for i = 0 to request.form("belopp").count
  4.   objconn.execute("update lander_belopp set belopp='" & request.form("belopp")(i) & "'")
  5.   next
  6. end if
  7.  
Sep 8 '07 #1
10 1506
Anyone that can help me whit this. maybe a simple awnser but whould be nice whit help =)
Sep 8 '07 #2
markrawlingson
346 Expert 100+
What are you trying to do? Are you trying to insert multiple records into a single table - or are you trying to insert 1 record into a single table, but are updating numerous columns within that table?

Judging by the code below it looks like you're trying to insert multiple records and are simply updating 1 column..

dim i
if request.querystring("do") = "spara_traktamente" then
for i = 0 to request.form("belopp").count
objconn.execute("update lander_belopp set belopp='" & request.form("belopp")(i) & "'")
next
end if
If that's the case, you could try this..

Expand|Select|Wrap|Line Numbers
  1. If Request.QueryString("do") = "spara_traktamente" Then
  2.   For Each oItem In Request.Form
  3.      If oItem = "belopp" Then
  4.         objconn.execute("update lander_belopp set belopp='" & request.form(oItem) & "')"
  5.      End If
  6.   Next
  7. End If
  8.  
This will basically Loop through the entire Request.Form object, and if the information is coming from a field called "belopp" it will insert a new record into your table.
Sep 8 '07 #3
The code you postet is what i want to do but dont work. i changed it a bit but get this

Microsoft JET Database Engine error '80040e07'

Data type mismatch in criteria expression.

Here is the modifyed:
Expand|Select|Wrap|Line Numbers
  1. If Request.QueryString("do") = "spara_traktamente" Then
  2. For Each oItem In Request.Form
  3. If oItem = "belopp" Then
  4.  
  5. objconn.execute("update lander_belopp set belopp='" & request.form(oitem) & "'")&""
  6. End If
  7. Next
  8. End If
  9.  
Sep 9 '07 #4
Dont get it to work, i get Syntax error in UPDATE statement.
Sep 11 '07 #5
Now i have tried to get this to work but i wont. Whats the problem exactly, can someone give me a hint. I know what the error says but how i turn and twist this it wont work. so should be great whit some more help.
Sep 17 '07 #6
markrawlingson
346 Expert 100+
Well,

Any information coming back from the request.form object is automatically a string type. So what data type is your belopp field? It's not a string, and you're trying to throw a strong type variable into it.. it'll throw an error, so you'll have to treat the request.form(oItem) object first to change it from a string value to the context which you need it to be.

The other thing I noticed is at the end of your execute statment you have a couple of double quotes handing around...

Expand|Select|Wrap|Line Numbers
  1. objconn.execute("update lander_belopp set belopp='" & request.form(oitem) & "'")&""
  2.  
You don't need the &"" there after the ) ending the execute statement, not sure why you put them there for?

Sincerely,
Mark
Sep 17 '07 #7
The ending on the code did get wrong, i saw it when i had posted it so the extra dose not exist.

The datatype for the colum belopp is Number. and the value its suppose to put in is a number. =).

The code looks like this now.
Expand|Select|Wrap|Line Numbers
  1.       If Request.QueryString("do") = "spara_traktamente" Then
  2.       For Each oItem In Request.Form
  3.       If oItem = "belopp" Then
  4.  
  5.       objconn.execute("update lander_belopp set belopp=" &    request.form("oItem") & "")
  6.         End If
  7.         Next
  8.        End If
  9.  
Sep 17 '07 #8
markrawlingson
346 Expert 100+
Yeah I figured as much, that's why you're getting the error. Anything that comes back from the Request.Form object will be returned as string data type. I guess I should have mentioned that before - my bad!

You could use CInt wrapped around the data to convert it to a number, but my collegue and I wrote a more sophisticated version of string to numerical conversion as shared with you below. The VAL() function will convert a string to a numerical value, keeps decimal values, will return 0 if the string it's searching does not contain a numerical value, or will entirely rip out any text within the string, returning just the numerical value if one exists. I would use this.. very straight forward and no further work involved.

Expand|Select|Wrap|Line Numbers
  1.   Function Val( sValuePrivate )
  2.     Set oRegExp = New RegExp
  3.     oRegExp.Pattern = "[^0123456789\.]"
  4.     oRegExp.IgnoreCase = True
  5.     oRegExp.Global = True
  6.     Val = Abs( oRegExp.Replace( "0" & sValuePrivate, "" ) )
  7.     Set oRegExp = Nothing
  8.   End Function
  9.  
Example:

Val("Hello my name is 123") - returns 123
Val("Hello my name is Mark") - returns 0
Val("12345") - returns 12345
Val("") - returns 0 (good way to check null/empty values)

Hope this helps
Sincerely,
Mark
Sep 17 '07 #9
Really good man. Thumbs up, but how do i use the function whit the code?
Sep 17 '07 #10
Should i just replace "oitem" whit "oRegExp" ? The thing is the only thing that you type in in the textbox is a number so dont follow why i should have a function thats just take the numbers in the textbox, thats the only thing you will be writing.
Sep 17 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

17 posts views Thread by kalamos | last post: by
32 posts views Thread by tshad | last post: by
4 posts views Thread by rn5a | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.