How to Create a New Data Entry Website

Save

When you have numerous records to insert into a database, sometimes it's just easier to create a small website for data entry personnel. Creating a data entry website involves a web form and coding that inserts the new record into the database. For faster processing, the web page returns to the original page where the web form is placed. The process is repeated, and it makes it more efficient and faster to insert data.

Things You'll Need

  • Visual Studio .NET

Create the Form

  • Create a new ASPX page by clicking the Visual Studio "File" menu and selecting "New." A list of file types is shown. Select HTML or ASPX. Either one will work for a small data entry page. In this example, ASPX is used.

  • Create the form elements. The number of elements on a form are determined by the amount of information needed for data entry. In this example, the website is only entering first name and last name for customers. Use this code:
    <asp:TextBox id="first_name" runat="server" />
    <asp:TextBox id="last_name" runat="server" />

  • Insert the submit button. Forms require a submit button, so add the following code to the web page:
    <asp:Button id="btnSubmit" Text="Submit Me" runat="server" />

  • Double-click on the button that was just created. A code-behind page appears that creates an event, which is triggered when the user clicks the button. An event is a type of function that runs code when a user interacts with a program. For instance, clicking a button triggers the "onClick" event and changing a drop-down box selection triggers the "onChange" event.

Insert Information into the Database

  • Assign the user's input to a string variable. First, double-click the button that was created in Section 1. This opens the "onClick" event where you place the code that inserts the information into a database. When the user presses the button created in Section 1, the form data is sent for processing. Following is the code that references the submitted form values and assigns it to a variable:

    string first_name = first_name.Text;
    string last_name = last_name.Text;

    This code is placed at the very beginning of your "onClick" event function.

  • Create a query to insert data into the database. .NET comes with classes that make it easy to insert data into a database. Add this line under the code in step 1. This query is the code that inserts information into the database. It uses the user's information saved in the variables from Step 1 and creates a record in the database table. Following is a sample of an SQL insert statement:

    string query = "insert into customer (first_name, last_name) values ('" + first_name + "', '" + last_name + "')";

  • Create a connection to the database. Add the following line below below the code entered from Step 2. This sets up the database connection to your server; it is required for any data entry page.

    myConn = new SqlConnection("Data Source=SQLServer;Initial Catalog=myDatabase;User Id=user;password=password");

  • Create the SQL command and run the query. Enter this line of code after the database connection. This command executes the query on the server and inserts the new record to the customer database:

    SqlCommand myCmd = new SqlCommand(query, myConn);
    myCmd.ExecuteNonQuery();

  • Notify the user that the text as been entered. Once the data has been inserted, it's common practice to notify the reader that the command has completed successfully. Add this line of code after the command from Step 4. The following code writes a notification to the web page so users are aware that the process is complete:

    Response.Write("The data has been successfully saved!");

References

Promoted By Zergnet

Comments

You May Also Like

Related Searches

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!