Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    insert sql command and vb.net that inserts different values in each row till it is 50

    I am trying to write an insert statement that loops through the database and inserts values like this automatically. See how it goes a, b, c, d and 1,1,1,1 how do you tell it to do that.
    INSERT INTO TBL_SEAT (SEAT_NUM, SEAT_ROW, SEAT_TYPE, PLANE_ID) VALUES ('A', 1, 'WINDOW', 3434278231);
    INSERT INTO TBL_SEAT (SEAT_NUM, SEAT_ROW, SEAT_TYPE, PLANE_ID) VALUES ('B', 1, 'AISLE', 3434278231);
    INSERT INTO TBL_SEAT (SEAT_NUM, SEAT_ROW, SEAT_TYPE, PLANE_ID) VALUES ('C', 1, 'AISLE', 3434278231);
    INSERT INTO TBL_SEAT (SEAT_NUM, SEAT_ROW, SEAT_TYPE, PLANE_ID) VALUES ('D', 1, 'WINDOW', 3434278231);
    INSERT INTO TBL_SEAT (SEAT_NUM, SEAT_ROW, SEAT_TYPE, PLANE_ID) VALUES ('A', 2, 'WINDOW', 3434278231);
    INSERT INTO TBL_SEAT (SEAT_NUM, SEAT_ROW, SEAT_TYPE, PLANE_ID) VALUES ('B', 2, 'AISLE', 3434278231);
    INSERT INTO TBL_SEAT (SEAT_NUM, SEAT_ROW, SEAT_TYPE, PLANE_ID) VALUES ('C', 2, 'AISLE', 3434278231);
    INSERT INTO TBL_SEAT (SEAT_NUM, SEAT_ROW, SEAT_TYPE, PLANE_ID) VALUES ('D', 2, 'WINDOW', 3434278231);
    but it needs to stop after it has inserted 50 rows.

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts

    this should work

    PHP Code:
    char seatNum[4]= 'a''b''c''d';
    int finished 0;
    for(
    int seatType =0finished 50seatType++){
        for(
    int j 04j++){
            
    output this partseatNum[j], seatType;
            
    finished++;
        }

    You should tell me what language you are using. some language works differently. like c allow char++.

    hope this help

  • #3
    New Coder
    Join Date
    Oct 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sorry i am using vb.net...check this out though.

    Code:
      Dim NumberOfRows As Integer = 10
            Dim NumberOfColumns As Integer = 4
            Dim PlaneID As String = "3434278231"
            Dim SeatType As String
            Dim i As Integer
            Dim j As Integer
    
            For i = 1 To NumberOfRows
                For j = 1 To NumberOfColumns
                    If j = 2 Or j = 4 Then
                        'Assuming B & D are Window Seats (j=1 For A, 2 for B and so on)
                        SeatType = "Window"
                    Else
                        SeatType = "Aisle"
                    End If
                    Qry = String.Format("INSERT INTO TBL_SEAT (SEAT_NUM, SEAT_ROW, SEAT_TYPE, PLANE_ID) VALUES ('{0}', {1},'{2}', '{3}');", Chr(64 + j), i, SeatType, PlaneID)
                    MsgBox(Qry)
                Next j
            Next i

    can you help me with what '{0}', {1},'{2}', '{3}');", Chr(64 + j) actually does?


  •  

    Posting Permissions

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