I have a table like these:
Club Table contains: ClubID(IDENTITY), Name, Address
Genre table contains: GenreID and Genre
ClubGenre table contains Club ID, GenreID
Club has a one to many relationship with Genre
I created an application that functions like a database editor. I have a group of checkbox contained in a group box labeled Genres. It contains the Genre in the Genre table. This is not databound though, I typed it manually. I'm having troubles with my Add/Save button. What I'm basically trying to do is this
- Click New record button
- textboxes and checkboxes will be enabled
- input data
- click save
- Insert Name and address into club table (I know how to do it up to this part)
Since my ClubID is IDENTITY, it will be auto generated right. I need this ClubID to insert data into my ClubGenre table.
Let's say checkbox 1 labeled Pop is checked . In my genre table, it contains a record namely 1 as genreID and Pop as genre
This means my insert statement will be like:
INSERT INTO Genre VALUES(*thenewlyaddedClubID*,1)
Now if checkbox 1,3,5 are checked it will be like:
INSERT INTO Genre VALUES(*thenewlyaddedClubID*,1)
INSERT INTO Genre VALUES(*thenewlyaddedClubID*,3)
INSERT INTO Genre VALUES(*thenewlyaddedClubID*,5)
I've come up with a solution in retrieving the newly added CLUB ID but can't put it all together yet. I'm thinking of putting the new clubID in a hidden textbox using the statement
SELECT MAX(clubID) AS barid FROM club