We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to perform CRUD operations with ASP SqlDataSource?

The SqlDataSource is used to access data that is in relational database. The Grid fetches the data based on the SELECT command of the ASP SqlDataSource control.

We will see in detail on how to perform CRUD operations directly to database using asp sqlDataSource

Solution:

We can achieve the above requirement by using the InsertCommand, UpdateCommand and DeleteCommand properties of the asp SqlDataSource.

Example:

In the following example, we have rendered a grid with CRUD enabled.

  1. Render the grid

ASP

 

 

  1. Using the InsertCommand, UpdateCommand and DeleteCommand properties of the sqlDataSource, write the sql command corresponding to insert, update and delete operation in grid

 

 

We can pass the parameters corresponding to insert and update operations using the Insertparameters and UpdateParameters properties of the SqlDataSource.

Note: If the IsIdentity property for a column is set in the database, it is not necessary to define the column within the InsertCommand property as the column value will be automatically generated and thus will conflict with the value we pass. 

Article ID: Published Date: Last Revised Date: Platform: Control:
7423 02/13/2017 02/13/2017 ASP.NET Web Forms Grid
Tags:
Did you find this information helpful?
Comments
Jurica Banic Dec 06, 2017

Hi,

I am not really clear how this is suppose to work? Noting happens whit this. New record is added to grid only but not saved to database. What I am missing?

Not also sure why you are binding data to grid on a page load? this.Grid even does not exist.

You're help would be apreciated as I would like to use SqlDataSource for CRUD operations.

Thanks

Reply
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.