New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Configure SqlDatSource for CRUD operations
Updated over 6 months ago
SqlDataSource Configuration
Add a SqlDataSource component to the Page and configure the following properties:
ConnectionString- Set a connection string to connect to the SQL database. For examples, check out the SQL Server connection strings article.SelectCommand- SQL compliantSELECTquery to select records from the database.InsertCommand- SQL compliantINSERTquery to insert records to the database.UpdateCommand- SQL compliantUPDATEquery to update records in the database.DeleteCommand- SQL compliantDELETEquery to delete records from the database.
For security purposes, it is recommended to add parameters for every Command that uses
@parameters.
SelectParametersInsertParametersUpdateParametersDeleteParameters
Example
ASP.NET
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [OrderID], [OrderDate], [Freight], [ShipName], [ShipCountry] FROM [Orders]"
InsertCommand="INSERT INTO [Orders] ([OrderDate], [Freight], [ShipName], [ShipCountry]) VALUES (@OrderDate, @Freight, @ShipName, @ShipCountry)"
UpdateCommand="UPDATE [Orders] SET [OrderDate] = @OrderDate, [Freight] = @Freight, [ShipName] = @ShipName, [ShipCountry] = @ShipCountry WHERE [OrderID] = @OrderID"
DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = @OrderID">
<InsertParameters>
<asp:Parameter Name="OrderDate" DbType="DateTime" />
<asp:Parameter Name="Freight" DbType="Decimal" />
<asp:Parameter Name="ShipName" DbType="String" />
<asp:Parameter Name="ShipCountry" DbType="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="OrderID" DbType="Int32" />
<asp:Parameter Name="OrderDate" DbType="DateTime" />
<asp:Parameter Name="Freight" DbType="Decimal" />
<asp:Parameter Name="ShipName" DbType="String" />
<asp:Parameter Name="ShipCountry" DbType="String" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="OrderID" DbType="Int32" />
</DeleteParameters>
</asp:SqlDataSource>