0

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?

2 Answers2

0

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

mgnoonan
  • 7,060
  • 5
  • 24
  • 27
0

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
Icarus
  • 63,293
  • 14
  • 100
  • 115
  • So there is no harm in using just the aspnetdb file? – Daniel Jayne Apr 17 '12 at 15:29
  • If you run aspnet_regsql.exe to create the tables, etc., you can also choose an existing database in which to create them. – Tuan Apr 17 '12 at 15:44
  • @DanielJayne I don't see a problem with using `aspnetdb.mdf` for your purpose. The `aspnet_regsql.exe` tool simply adds a bunch of tables and procedures that support some features out of the box (such as membership, role management, etc). Read more here: http://msdn.microsoft.com/en-us/library/x28wfk74.aspx – Icarus Apr 17 '12 at 16:00