Question

Firstly, I'm new. I'm creating a website in .NET and am getting confused by a few things. When using a CreateUserWizard control, a database file called aspnetdb.mdf is created automatically. I am creating a Blackjack game and thus need to initialise values such as totalWins, totalGamesPlayed etc. for each user. My question is, what is the best method to do so in .NET? Should I add fields to the Users table in aspnetdb.mdf or create a seperate file with a Users table? Eitherway, how do I populate this table adding a new record for each new user?

Was it helpful?

Solution

I would not mess around with the Users table in aspnetdb.mdf since it's meant to contain personal information such as username, etc. You should create a separate table called User_Score and work off of that one. You can create a foreign key to the Users table using the user_id (or whatever the suitable key should be).

As far as populating the data initially, there are many approaches to this, one could be having a trigger that will initialize a record in the User_Score table as soon as a record is created in the User table.

One approach would be creating a trigger similar to this in the User table:

CREATE TRIGGER myTrigger 
   ON User 
   AFTER INSERT
AS BEGIN
   -- INSERT RECORD IN THE User_Score table here
   -- populating the appropriate fields. Example:
  INSERT INTO User_Score (username,columna, columnb, columnc) 
  SELECT username, 0,0,0 from inserted
END

OTHER TIPS

You want to use the Profiles feature, also built-in to .NET.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top