Query insert into

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viki1967
    Contributor
    • Oct 2007
    • 263

    Query insert into

    Hi all.

    I have this values:

    Code:
    R, S, T, G
    1, 2, 3, 4
    1, 2, 3, 4
    1, 2, 3, 4
    1, 2, 3, 4
    1, 2, 3, 4
    P, N, P, N
    BF, CC, BF, CC
    I need insert this values in the table of db mysql in this mode:


    Code:
    TEST	A	B	C	D	E	F
    
    R	    1	 1  1	1	P	BF
    S	    2	 2  2	2	N	CC
    T	    3	 3  3	3	P	BF
    G	    4	 4  4	4	N	CC

    Can you help me?
    thanks
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi viki,

    What is it exactly that you don't know how to do? Do you know how to insert data into a MySQL database? Or is it converting the data into the required format to insert it that's causing you problems?

    How are you receiving this data e.g. XML File, text file, form submission etc.

    Dr B

    Comment

    • viki1967
      Contributor
      • Oct 2007
      • 263

      #3
      Hi Dr. , thanks x your answer.

      The code ASP this is:

      Code:
      response.write trim(request.form("fase")) &"<br>" &_
                     trim(request.form("V_prova")) &"<br>" &_
                     trim(request.form("I_prova")) &"<br>" &_
                     trim(request.form("V_scarica")) &"<br>" &_
                     trim(request.form("durata")) &"<br>" &_
                     trim(request.form("V_applicata")) &"<br>" &_
                     trim(request.form("esito")) &"<br>" &_
                     trim(request.form("modalita")) &"<br><br>"
      
      ReDim arrayForm(1, 255)
      intIndice = 0
      
      For Each varItem in Request.Form
      If Request.Form(varItem).count > 1 Then
      
      For intLoop = 1 to Request.Form(varItem).count 
      
      arrayForm(0, intIndice) = varItem & "(" & intLoop & ")"
      arrayForm(1, intIndice) = Request.Form(varItem)(intLoop)
      intIndice = intIndice + 1
      Next
      Else 
      
      arrayForm(0, intIndice) = varItem
      arrayForm(1, intIndice) = Request.Form(varItem)
      intIndice = intIndice + 1
      End If
      Next
      
      ReDim Preserve arrayForm(1, intIndice - 1)
      
      For intIndice = 0 To UBound(arrayForm, 2)
      Response.Write arrayForm(0, intIndice) & " = " _
      & arrayForm(1, intIndice) & "<BR>"
      
      strSQL = "INSERT INTO " 
      strSQL = strSQL & "  tbl_2 " 
      strSQL = strSQL & " ( " 
      strSQL = strSQL & "  PROVA, "
      strSQL = strSQL & "  A, "
      strSQL = strSQL & "  B, "
      strSQL = strSQL & "  C, "
      strSQL = strSQL & "  D, "
      strSQL = strSQL & "  E, "
      strSQL = strSQL & "  F "
      strSQL = strSQL & " ) " 
      strSQL = strSQL & " VALUES " 
      strSQL = strSQL & " ( " 
      strSQL = strSQL & " '" & arrayForm1(i) & "', "
      strSQL = strSQL & "  " & arrayForm2(i) & ", "
      strSQL = strSQL & "  " & arrayForm3(i) & ", "
      strSQL = strSQL & "  " & arrayForm4(i) & ", "
      strSQL = strSQL & "  " & arrayForm5(i) & ", "
      strSQL = strSQL & " '" & arrayForm6(i) & "', "
      strSQL = strSQL & " '" & arrayForm7(i) & "' "
      strSQL = strSQL & " ) " 
      cn.execute(strSQL)
      
      Next
      The error in the query is:

      Error Type:
      Error run-time Microsoft VBScript (0x800A0009)

      Why?

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Your array is out of range. Which line is it erroring on?

        Comment

        • viki1967
          Contributor
          • Oct 2007
          • 263

          #5
          Hi Dr.

          My problem is this.

          I have this values of request.form:

          Code:
          A, B, C
          1, 5, 9
          I see this values for column and insert in the db mysql in this mode:

          Code:
          INSERT INTO MyTbl ( Text, Number ) VALUES ( 'A', 1 )
          INSERT INTO MyTbl ( Text, Number ) VALUES ( 'B', 5 )
          INSERT INTO MyTbl ( Text, Number ) VALUES ( 'C', 9 )
          Do you understand my?

          Comment

          • viki1967
            Contributor
            • Oct 2007
            • 263

            #6
            All ok people!!!!

            The solution is:

            Code:
            INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
            Property of db mysql:

            Comment

            Working...