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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to perform CRUD operations with ASP SqlDataSource?

Platform: ASP.NET Web Forms |
Control: Grid
Tags: grid, crud

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


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


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

  1. Render the grid


<ej:Grid ID="EmployeesGrid2" runat="server" AllowPaging="True" DataSourceID="SqlData" EnableLoadOnDemand="false"  DataSourceCachingMode="None">
    <EditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true" />
    <ToolbarSettings ToolbarItems="add,edit,delete,update,cancel" ShowToolbar="true"></ToolbarSettings>
        <ej:Column Field="OrderID" IsPrimaryKey="true"/>
        <ej:Column Field="EmployeeID" />            
        <ej:Column Field="Freight" Format="{0:c2}" />
        <ej:Column Field="ShipCity" />


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


<asp:SqlDataSource ID="SqlData" runat="server" ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>"
            SelectCommand="SELECT * FROM [Orders]" 
        InsertCommand="INSERT INTO [Orders] ([Freight], [EmployeeID], [ShipCity])
         VALUES (@Freight, @EmployeeID, @ShipCity)"
        "DELETE FROM [Orders] WHERE [OrderID] = @OrderID"
       UpdateCommand="UPDATE [Orders] SET 
         [Freight] = @Freight, [EmployeeID] = @EmployeeID, [ShipCity] = @ShipCity
        WHERE [OrderID] = @OrderID"> 
             <asp:Parameter Name="Freight" Type="Double" />
            <asp:Parameter Name="EmployeeID" Type="Int32" />
            <asp:Parameter Name="ShipCity" Type="String" />
            <asp:Parameter Name="Freight" Type="Double" />
            <asp:Parameter Name="EmployeeID" Type="Int32" />
            <asp:Parameter Name="ShipCity" Type="String" />
            <asp:Parameter Name="OrderID" Type="Int32" />


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


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. 


2X faster development

The ultimate ASP.NET Web Forms UI toolkit to boost your development speed.
You must log in to leave a comment
Jurica Banic
Dec 06, 2017


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.



Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile