Step 1:create a table.
Step 2:
<asp:SqlDataSource ID="sdsEmp" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
SelectCommand="SELECT * FROM [Employee]"
DeleteCommand="DELETE FROM [Employee] WHERE [EmpId] = @EmpId"
UpdateCommand="UPDATE [Employee] SET [EmpName] = @EmpName, [City] = @City WHERE [EmpId] = @EmpId">
<DeleteParameters>
<asp:Parameter Name="EmpId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="EmpName" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="EmpId" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="gvEmp" runat="server" DataSourceID="sdsEmp"
AutoGenerateColumns="False" DataKeyNames="EmpId" AllowPaging="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="EmpId" HeaderText="EmpId" InsertVisible="False"
ReadOnly="True" SortExpression="EmpId" />
<asp:BoundField DataField="EmpName" HeaderText="EmpName"
SortExpression="EmpName" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
</Columns>
</asp:GridView>
In web.config file add
the code:
<configuration>
<connectionStrings>
<add name="DataBindDBConnectionString" connectionString="Data Source=[server Name];Initial Catalog=[Table Name];Integrated Security=true;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
</configuration>
Step 2:
<asp:SqlDataSource ID="sdsEmp" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
SelectCommand="SELECT * FROM [Employee]"
DeleteCommand="DELETE FROM [Employee] WHERE [EmpId] = @EmpId"
UpdateCommand="UPDATE [Employee] SET [EmpName] = @EmpName, [City] = @City WHERE [EmpId] = @EmpId">
<DeleteParameters>
<asp:Parameter Name="EmpId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="EmpName" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="EmpId" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="gvEmp" runat="server" DataSourceID="sdsEmp"
AutoGenerateColumns="False" DataKeyNames="EmpId" AllowPaging="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="EmpId" HeaderText="EmpId" InsertVisible="False"
ReadOnly="True" SortExpression="EmpId" />
<asp:BoundField DataField="EmpName" HeaderText="EmpName"
SortExpression="EmpName" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
</Columns>
</asp:GridView>
In web.config file add
the code:
<configuration>
<connectionStrings>
<add name="DataBindDBConnectionString" connectionString="Data Source=[server Name];Initial Catalog=[Table Name];Integrated Security=true;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
</configuration>
To know about such things in more detail visit us at bestdotnettraining
Comments
Post a Comment