Database Storage with the ASP.NET Web Matrix - Create a database and table
(Page 2 of 6 )
First then, you can create the database and table that will store the usernames and passwords of your visitors. To do this, click on the Data tab on the right-hand side of the application and select the Add Database Connection button. This will open the Add New Project dialogue box, where you can select the SQL Server database. In the Connect to Database dialog box, click the link at the bottom entitled Create a new database. You’ll be prompted to choose a name for the new database, so enter something relevant, like "members." The connection will now show in the Data panel.

To add a table to the database, in which to actually store the information, expand the new connection and highlight the tables folder. Click the New Database Object button and enter a name for the table. Again, use a name that makes sense, such as "logins." The table interface will now be displayed. We’ll keep it basic for this exercise and just create two columns -- one to store the usernames, and one to store the associated passwords. The first column has been created for you; highlight it and click into the Name field. Enter Username and then click into the DataType field. A pointer will appear, allowing you to expand the selection. Choose char. Now click into the Size field and set a limit of 20 characters. Finally, scroll down to the bottom and set the IsUniqueKey option to true, specifying that the table cannot contain duplicate Usernames.
Click the New button to add another column, set the Name to Password and set the rest of the properties as above.

Click the cross button in the top right-hand corner of the table interface to close the window. You will get a message advising that no primary key has been set, but choose to save the table anyway. This means that you will not be able to edit the data in the table, but for this basic example, you don’t need to. Your new table will now appear under the tables folder of the database connection.

Next: Setting up a registration page >>
More Database Articles
More By Dan Wellman