How to Create a Web Interface SQL to Populate a Database

The Microsoft .NET Frameworks works with the SQL Server database to store information in the tables. The information entered into a Web page form stores to the SQL database using a database connection and query. The drivers and classes used to send the information to the database are supplied by the .NET Framework. Use these two applications together to populate a database table with information.

Instructions

    • 1

      Open the Visual Studio software from the Windows program menu. Open your Web project and double-click the form you want to use to create the input form.

    • 2

      Drag and drop a text box control from the VS toolbox to the form. In the Properties panel, name the text box "name." This text box allows users to insert a name that is inserted into the database table. Add additional text boxes for each piece of data you want to insert into the database.

    • 3

      Double-click the source code file for the Web page form. Add the following code to the top of the file to import the necessary namespace:

      using System.Data;
      using System.Data.SqlClient;

    • 4

      Scroll down to the "Submit" event to add the code that inserts the data into the database. Create a database connection. Add the following code to connect to the SQL Server:

      SqlConnection connect = new SqlConnection("server=localhost;uid=username;pwd=password;database=db;")
      connect.Open();

      Replace the username and password with your own. Change "db" with the name of your database.

    • 5

      Insert the data into the SQL Server tables. The following code inserts the "name" text box into the database table "customers":

      SqlCommand sqlComm = new SqlCommand("insert into customers (name) values ('" + name.Text + "'", connect);

      You add each text box in the "insert" statement to add more data to the table.

    • 6

      Click the "Save" button and "Run" to run the page in the VS debugger. Enter information and click "Submit" to insert data into your database.

Related Searches:

References

Comments

Related Ads

Featured