Execute delete command with SqlCommand against SqlServer : SqlServer « ADO.net Database « ASP.NET Tutorial

<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
    void Page_Load(object sender, EventArgs e) {
        string ConnectionString = ConfigurationSettings.AppSettings["MSDEConnectString"];
        SqlConnection myConnection = new SqlConnection(ConnectionString);
            string CommandText = "DELETE FROM Publisher WHERE PublisherID = 6";
            SqlCommand myCommand = new SqlCommand(CommandText, myConnection);
            lblRecords.Text = Convert.ToString(myCommand.ExecuteNonQuery());
        } catch (Exception ex){
        } finally{

    <form runat="server">
        Records affected: <asp:Label id="lblRecords" runat="server"></asp:Label>

File: Web.config

        <add key="MSDEConnectString" value="server=(local)\YourDatabaseAddress;database=Books;uid=YourID;pwd=letmein;" />

18.42.1.Connect to SQL server with integrated Authentication or SQL Authentication
18.42.2.Execute delete command with SqlCommand against SqlServer
18.42.3.You can connect to a Local database named MyLocalData.mdf by using the following connection string:
18.42.4.For example, the following connection string enables you to connect to a Server database named MyData:
18.42.5.You use SQLCMD by opening a command prompt and connecting to your database with the following command:
18.42.6.Read data from SQL server and fill asp:dropdownlist (C#)
18.42.7.Handle table relationship (C#)
18.42.8.Insert, update and delete (C#)