Submitting input from a form to an Access database

In FrontPage, you had the ability to make an html form, Right-Click on it, and invoke a Wizard that would allow you to create an Access database and send the form data to the database. While you can do the same in Expression, the html forms are notoriously vulnerable to spam robots, and a far better solution is to use ASP.NET forms to send data to a database, since the form validation controls can be used creatively to prevent robot access.

This tutorial provides the step-by-step process to send your data to a database using the ASP.NET controls. We will use an Access database, but most any database could be used.

First, you need to create the database which will be receiving the form input. Since we will be using Access, you do need to have a copy of Access on your computer to create the database.

Open Access and make a new simple, single table database. Call it OneTable.mdb, open a new table in Design View put these fields in it:

"FName" of type: "Text"

"LName" of type "Text"

"Phone" of type "Number" and Format "Double"

"Payment" of type "Currency" with 2 decimal places

"Percent" of type "Number", Format "General Number" and field size "Decimal"

Save this table with the name "OnlyTable" and switch to the normal table view and fill in five or six records and save it (you will be prompted to generate a unique key, which you should do, resulting in an ID column with an Autonumber field Access generates for you). Now you are ready to start working with Expression using this database table.

Open Expression, and with a website open, click on the Folder List tab, click to highlight the fpdb folder, and do File / Import, browse to OneTable.mdb and import it. That should result in the database being present in your fpbd folder, and you are now ready to make an aspx page wth a form on it that will submit a record to the database.

1. Make new page called SubmitForm.aspx and open it. All you have on the page is the outline of a one-line empty form. In the Tag properties for the form, change the ID of the form to something sensible like InputForm

2. Now drag a FormView control onto the form from the ASP.NET data controls window. In the Tag Properties pane, change the ID from FormView1 to something sensible like InputForm

3. Important step: In the tag properties for the FormView, go to DefaultMode and from the dropdown list, change ReadOnly to "Insert" which causes the FormView to automatically use the InsertItemTemplate

4. Click on the expander arrow at top right of the control and select "new data source" from the choose data source window

5. Click on Access Database and change the name from AccessDataSource1 to something sensible like SingleTableDatabase (no spaces) since that is the database we will be using. Click OK. Click the Browse button and browse to the fpdb folder, highlight OneTable.mdb, click Open, then Next

6. In the Configure the Select Statement that comes up, you should see the table "OnlyTable". Select the * column, click Advanced, and select "Generate insert, delete, and update statements", and click OK. Note: If instead of selecting * which brings up all fields, you can check the boxes for the fields you wish to bring up. However, in order to have the insert, delete, and update queries automatically generated, you must include the primary key for the table. Also note that if you happen to be working with one table of a multi-table relational database, those queries will not be generated if the result is trying to modify more than a single table.

Click Next, TestQuery, and Finish

You are done. Save, and preview the file in Browser. When you enter data into the fields and hit insert, it will not be obvious that a record has been added to the database, but it has.

If you have a GridView on another page set up to view the database records, you will see the new record showing up there. To see how to set up such a GridView display of database results, see this tutorial  .

Like how fast this site is? I use and recommend  Arvixe  for asp.net hosting
Copyright Information: All graphics on this site are copyrighted and may not be used.