Automatically Generating the INSERT, UPDATE, and DELETE Statements

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CRUD_GRIDVIEW._Default" %>


<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">


    <table class="w-100">

        <tr>

            <td>

                <asp:GridView ID="GridView1" runat="server" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black" AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="Id">

                    <Columns>

                        <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />

                        <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />

                        <asp:BoundField DataField="gender" HeaderText="gender" SortExpression="gender" />

                        <asp:BoundField DataField="class" HeaderText="class" SortExpression="class" />

                    </Columns>

                    <FooterStyle BackColor="#CCCCCC" />

                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />

                    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />

                    <RowStyle BackColor="White" />

                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />

                    <SortedAscendingCellStyle BackColor="#F1F1F1" />

                    <SortedAscendingHeaderStyle BackColor="#808080" />

                    <SortedDescendingCellStyle BackColor="#CAC9C9" />

                    <SortedDescendingHeaderStyle BackColor="#383838" />


                </asp:GridView>

            </td>

            <td>&nbsp;</td>

        </tr>

        <tr>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

        </tr>

        <tr>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

        </tr>

        <tr>

            <td>

                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Crud_DbConnectionString %>" SelectCommand="SELECT * FROM [Student]" InsertCommand="INSERT INTO [Student] ([name], [gender], [class]) VALUES (@name, @gender, @class)" DeleteCommand="DELETE FROM [Student] WHERE [Id] = @Id" UpdateCommand="UPDATE [Student] SET [name] = @name, [gender] = @gender, [class] = @class WHERE [Id] = @Id" ProviderName="<%$ ConnectionStrings:Crud_DbConnectionString.ProviderName %>">

                    <DeleteParameters>

                        <asp:Parameter Name="Id" Type="Int32"/>

                    </DeleteParameters>

                    <UpdateParameters>

                        <asp:Parameter Name="name" Type="String"/>

                        <asp:Parameter Name="gender" Type="String"/>

                        <asp:Parameter Name="class" Type="Int32"/>

                        <asp:Parameter Name="Id" Type="Int32"/>

                    </UpdateParameters>

                    <InsertParameters>

                        <asp:Parameter Name="name" Type="String"/>

                        <asp:Parameter Name="gender" Type="String"/>

                        <asp:Parameter Name="class" Type="Int32"/>

                    </InsertParameters>

                </asp:SqlDataSource>

            </td>

        </tr>

    </table>

Comments

Popular posts from this blog

Create a User Registration Form in ASP.NET using SQL Server, Visual Studio 2022 & Bootstrap

Create a Simple Login Form in ASP.NET using Visual Studio 2022

SqlCommand Class ADO.Net | ExecuteNonQuery | ExecuteReader | ExecuteScalar