Conflictdetection Property of Objectdatasource Control - Part 16

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

8/28/2017 Sql server, .

net and c# video tutorial: ConflictDetection property of objectdatasource control - Part 16

More Next Blog Create Blog Sign In

Sql server, .net and c# video tutorial


Free C#, .Net and Sql server video tutorial for beginners and intermediate programmers.

Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

ConflictDetection property of objectdatasource control - Part 16

Suggested Videos
Part 13 - Deleting data from gridview using sqldatasource control
Part 14 - ConflictDetection property of SqlDataSource control
Part 15 - Deleting data from gridview using objectdatasource control
Best software training and placements in
marathahalli, bangalore. For further
details please call 09945699393.

In Part 15 of the asp.net gridview tutorial we discussed about deleting data from
CBSE Class 9 Maths
gridview control using objectdatasource control. We did not discuss about concurrency
Number Systems
in Part 15. Let me explain what I mean.
1. When you access the webform, data is loaded into gridview control.
2. While you are looking at this data in the gridview control, someone else has updated CPT Tutorial
a row in the database table Part 1 : Video | Text | Slides
3. Now, in the gridview, when you click the delete button on the row that has changed,
the row gets deleted.
Important Videos
The Gift of Education

Web application for your business


This may be fine in most cases. However, let's say we don't want to allow the row to
be deleted, in case if it has changed, then, we can make use of ConflictDetection How to become .NET developer
property of the objectdatasource control.
Resources available to help you
We will be modifying the "DeleteEmployee()" method in
EmployeeDataAccessLayer.cs file. We discussed about this in Part 15. Please
Dot Net Video Tutorials
change the implementation of DeleteEmployee() method as shown below. Notice that
Angular 2 Tutorial
the ORIGINAL EmployeeId, Name, Gender and City are now passed as parameters to
the DeleteEmployee() method. These parameters are then used in the "DELETE"
Design Patterns
query, to check if the data has changed after it was loaded into the gridview control.
public static void DeleteEmployee(int original_EmployeeId, string original_Name, ASP.NET Web API
string original_Gender, string original_City)
{ Bootstrap
string CS =
ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString; AngularJS Tutorial
using (SqlConnection con = new SqlConnection(CS))
jQuery Tutorial
{
string deleteQuery = "DELETE FROM tblEmployee WHERE EmployeeId =
JavaScript with ASP.NET Tutorial
@original_EmployeeId " + "AND Name = @original_Name AND Gender =
@original_Gender AND City = @original_City"; JavaScript Tutorial
SqlCommand cmd = new SqlCommand(deleteQuery, con);
SqlParameter paramEmployeeId = new SqlParameter("@original_EmployeeId", Charts Tutorial
original_EmployeeId);
cmd.Parameters.Add(paramEmployeeId); LINQ
SqlParameter paramName = new SqlParameter("@original_Name",
LINQ to SQL
original_Name);
cmd.Parameters.Add(paramName);
LINQ to XML
SqlParameter paramGender = new SqlParameter("@original_Gender",
original_Gender); Entity Framework
cmd.Parameters.Add(paramGender);

http://csharp-video-tutorials.blogspot.in/2013/03/conflictdetection-property-of_6.html 1/4
8/28/2017 Sql server, .net and c# video tutorial: ConflictDetection property of objectdatasource control - Part 16
SqlParameter paramCity = new SqlParameter("@original_City", original_City); WCF
cmd.Parameters.Add(paramCity);
con.Open(); ASP.NET Web Services
cmd.ExecuteNonQuery();
Dot Net Basics
}
} C#

Compile the project and re-configure ObjectDataSource1 control, to use the above SQL Server
method as it's DELETE method.
ADO.NET
Finally on "ObjectDataSource1" control, set properties
ConflictDetection="CompareAllValues" ASP.NET
OldValuesParameterFormatString="original_{0}"
GridView

Setting ConflictDetection="CompareAllValues", will pass original values for ASP.NET MVC


EmployeeId, Name, Gender and City to DeleteEmployee() method.
Visual Studio Tips and Tricks
Notice the parameters of the DeleteEmployee() method. All of them have a prefix of
"original_". ObjectDataSource control uses "OldValuesParameterFormatString" property Dot Net Interview Questions
to figure out the exact name of the parameters for the original values. This is the reason
we have set OldValuesParameterFormatString="original_{0}" Slides
public static void DeleteEmployee(int original_EmployeeId, string original_Name, string
Entity Framework
original_Gender, string original_City)
WCF
At this point, the declarative HTML markup of gridview and objectdatasource
control, should be as shown below. ASP.NET Web Services
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1"> Dot Net Basics
<Columns>
C#
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="EmployeeId" HeaderText="EmployeeId"
SQL Server
SortExpression="EmployeeId" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ADO.NET
/>
<asp:BoundField DataField="Gender" HeaderText="Gender" ASP.NET
SortExpression="Gender" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" /> GridView
</Columns>
ASP.NET MVC
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
Visual Studio Tips and Tricks
SelectMethod="GetAllEmployees"
TypeName="Demo.EmployeeDataAccessLayer" DeleteMethod="DeleteEmployee"
OldValuesParameterFormatString="original_{0}" Java Video Tutorials
ConflictDetection="CompareAllValues"> Part 1 : Video | Text | Slides
<DeleteParameters>
<asp:Parameter Name="original_EmployeeId" Type="Int32" /> Part 2 : Video | Text | Slides
<asp:Parameter Name="original_Name" Type="String" />
Part 3 : Video | Text | Slides
<asp:Parameter Name="original_Gender" Type="String" />
<asp:Parameter Name="original_City" Type="String" />
</DeleteParameters> Interview Questions
</asp:ObjectDataSource> C#

SQL Server

Written Test

http://csharp-video-tutorials.blogspot.in/2013/03/conflictdetection-property-of_6.html 2/4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy