Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 5th, 2008, 03:03 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default Split value and insert into query

Hi all.

I have problem with this asp code:

Expand|Select|Wrap|Line Numbers
  1. strSplitDati = Split(request.Form("dati"), ",")
  2.  
  3.         for i = LBound(strSplitDati) to (INT(UBound(strSplitDati)/4)-1)*4 step 4
  4.  
  5.  
  6. strSql = " INSERT INTO "
  7. strSql = strSql & " tbl "
  8. strSql = strSql & " ( "
  9. strSql = strSql & " ID_UEV, "
  10. strSql = strSql & " UEV, "
  11. strSql = strSql & " testo_A, "
  12. strSql = strSql & " testo_B, "
  13. strSql = strSql & " numero_A, "
  14. strSql = strSql & " numero_B "
  15. strSql = strSql & " ) "
  16. strSql = strSql & "   VALUES "
  17. strSql = strSql & " ( "
  18. strSql = strSql & "   " & replace(strUEV(0), "'", "''") & ", "
  19. strSql = strSql & "  '" & replace(strUEV(1), "'", "''") & "', "
  20.  
  21.  
  22. if Trim(strSplitDati(i) & "[]") <> "[]" AND Trim(strSplitDati(i+1) & "[]") <> "[]" AND _
  23.    Trim(strSplitDati(i+2) & "[]") <> "[]" AND Trim(strSplitDati(i+3) & "[]") <> "[]" _
  24. then
  25.    strSql = strSql & ",'" & strSplitDati(i) & "' "
  26.    strSql = strSql & ",'" & strSplitDati(i+1) & "' "
  27.    strSql = strSql & "," & strSplitDati(i+2) & " "
  28.    strSql = strSql & "," & strSplitDati(i+3) & " "
  29.  
  30. else
  31.  
  32.    strSql = strSql & ", '-' "
  33.    strSql = strSql & ", '-' "
  34.    strSql = strSql & ", -1 "
  35.    strSql = strSql & ", -1 "  
  36.  
  37. end if
  38.  
  39. strSql = strSql & " ) "
  40. cn.execute strSql
  41.  
  42. response.write strSQL & "<br /><br />"
  43.  
  44. next
this code write this :

Quote:
INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', 'CS7' ,'Ins' ,1 ,2 )

INSERT INTO tbl ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', 'CS8' ,'Suf' ,3 ,4 )
and not this: why ????

Quote:
INSERT INTO tbly ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', '-' , '-' , -1 , -1 )

INSERT INTO tbly ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', 'CS7' ,'Ins' ,1 ,2 )

INSERT INTO tbly ( ID_UEV, UEV, testo_A, testo_B, numero_A, numero_B ) VALUES ( 1, 'TRLM', 'CS8' ,'Suf' ,3 ,4 )
Reply
  #2  
Old September 7th, 2008, 09:32 AM
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Age: 32
Posts: 2,363
Default

print out the request.form("dati"). What does it say?

My first impression is that your "for" statement is too complicated. It might be easier to say
Expand|Select|Wrap|Line Numbers
  1. for each i in strsplitdati
(i think that's what you are trying to do, but your statement is so complicated, I'm not sure I follow it.)

Jared
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles