Creating Data Base & Sql Data Source By huda AlSuwailem
First, click on App_Data folder.
Then, Right-click and choose Add New Item Then, Right-click and choose Add New Item. A dialog box will appear, select SQL Database. Type a name for the database.
Click on View, and select Server Explorer window Click on View, and select Server Explorer window. Double-click on your database then all files which are stored in this database will appear. Right-click on Table folder and choose Add New Table.
Create the fields you desire and choose their data types Create the fields you desire and choose their data types. Don’t forget to save your table. For example, create 2 fields “StudentID” and “StudentName”.
Add two textboxes to deal with the database.
Choose SqlDataSource from the Data section in the Toolbox window Choose SqlDataSource from the Data section in the Toolbox window. From the smart-tag click on Configure Data Source.
Choose the data connection you want to use to connect to the database, then click Next.
After that, select the first choice to add your Sql statement.
Write the SQL statement to select all table’s fields Write the SQL statement to select all table’s fields. Click Next then Finish.
Click on the InsertQuery from the Properties window Click on the InsertQuery from the Properties window. Write the insert command.
Create the Parameters.
After creating them, click ok.
Add a button control to your page, change its default text -which is “button”- to “insert”. Double-click the insert button and write the following code:
Click on the DeleteQuery from the Properties window Click on the DeleteQuery from the Properties window. Write the delete command. Create the Parameter(s) you need.
Click on the UpdateQuery from the Properties window Click on the UpdateQuery from the Properties window. Write the update command. Create the Parameter(s) you need.
Click on the SelectQuery from the Properties window Click on the SelectQuery from the Properties window. Write the select command. Create the Parameter(s) you need.
These are the codes you write in the buttons (Insert, Delete, Update, Select) :