...

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



jpalazzi
11-15-2004, 11:51 PM
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.

weronpc
11-16-2004, 04:34 PM
char seatNum[4]= 'a'. 'b', 'c', 'd';
int finished = 0;
for(int seatType =0; finished < 50; seatType++){
for(int j = 0; j < 4; j++){
output this part: seatNum[j], seatType;
finished++;
}
}

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

hope this help

jpalazzi
11-16-2004, 07:28 PM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum