SELECT, UPDATE, INSERT, DELETE directly from a GridView control
Posted Date: October 22, 2010
SELECT, UPDATE, INSERT, DELETE directly from a GridView control in ASP.Net 2.0
to Microsoft from all of us, who are involved in making websites with
ASP.Net. Why? Because, from ASP.Net 2.0, we have a very good news to
know; that is, selecting data from a database, updating data in a
database, inserting data in a database and delete data from a database
has become really easy by the use of GridView control. If you are using
ASP.Net 2.0 for making websites and thinking about to provide a very
user-friendly interface to your website users by which they will be able
to edit,update, delete data from the database, then I will suggest you
to use GridView control. It is really easiest and even you don't need to
write a single code for these heavy weighted operations. Now, let me
tell you how. Please follow the simple steps as below to do this:-
1) Drag and Drop a gridview control on the design page
2) Drag and Drop a SqlDataSource control on the design page
3) Click the smart tag window(a small arrow at the top right corner of the SqlDataSource control) of the SqlDataSource control
4) Click the "Configure DataSource" in the pop out window.
Now, you are in the "Choose Your Data Connection" section of the
wizard. Choose any existing data connection string or make a new one to
connect with the database, you are wanting to get the data from and
delete the data of.
6) Click "Next" button.
7) Now, you
are in the "Configure the Select Statement" section of the wizard.
Select "Specify a custom SQL statement or stored procedure".
8) Click "Next" button.
Now, you are in the "Define Custom Statement or Stored Procedures"
section of the wizard. Observe that there are four tags as
"SELECT","UPDATE","INSERT","DELETE". These tags are used for the
purposes as its name suggest. "SELECT" tag is for fetching data from the
database. If you want to get the data to be displayed in the gridview,
write down the SQL Statement here for fetching the data from the
database. "UPDATE" tag is for updating existing data in the database.
Write down the SQL Statement for updating the table of your choice(must
be in the database, you had made a connection string to connect with).
"DELETE" tag is for performing the delete operation to a database table,
so write down your SQL Statement for deleting data from a table of your
choice. The "INSERT" tag is used to insert new data in the database
directly from the gridview.
10) Click the "Next" button
Now, you are in the "Test Query" section of the wizard. Click the "Test
Query" button to see if your data is being correctly fetching from the
12) Click the "Finish" button.
Now, please run your application to see the results.
Happy Coding and Website Development
No response found. Be the first to respond this post
You must Sign In To post reply
|Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here|