http://www.youtube.com/user/kudvenkat...
Link for text version of this video
http://csharp-video-tutorials.blogspo...
In this video we will discuss about ConflictDetection property of SqlDataSource control. Please watch Part 13 of asp.net gridview tutorial before proceeding. In this example, we will be using tblEmployee table that we created in Part 13.
Drag and drop a GridView, Label and a SqlDataSource datasource control on WebForm1.aspx. Flip WebForm1.aspx to source mode and change the "ID" of Label control from "Label1" to "lblMessage". Flip WebForm1.aspx to design mode.
Now let's configure "SqlDataSource1" control
1. Right click on "SqlDataSource1" control and select "Show Smart Tag"
2. Now click on "Configure Data Source" link
3. Select connection string, from the dropdownlist on "Choose your data connection" screen. You need to have a connection string specified in web.config file.
4. Click Next
5. On "Configure the Select Statement" screen, select "tblEmployee" table from dropdownlist.
6. Click on "Advanced" button
7. Make sure you check CheckBoxes next to "Generate INSERT, UPDATE and DELETE statements" and "Use Optimistic Concurrency". Click OK.
8. Click Next and Finish
Now flip "WebForm1.aspx" to "HTML Source" mode. Notice that, the wizard has automatically generated INSERT, UPDATE and DELETE statements. Since, we only want to enable the gridview control to delete data, get rid of InsertCommand, InsertParameters, UpdateCommand, and UpdateParameters.
Since we have selected "Use Optimistic Concurrency" when configuring "SqlDataSource1" control, the generated "DeleteCommand" compares the row data with original values.
DeleteCommand="DELETE FROM [tblEmployee] WHERE [EmployeeId] = @original_EmployeeId AND (([Name] = @original_Name) OR ([Name] IS NULL AND @original_Name IS NULL)) AND (([Gender] = @original_Gender) OR ([Gender] IS NULL AND @original_Gender IS NULL)) AND (([City] = @original_City) OR ([City] IS NULL AND @original_City IS NULL))"
Also, ConflictDetection property is set to "CompareAllValues".
Had we not selected "Use Optimistic Concurrency" checkbox, the generated "DeleteCommand" would have been as shown below.
DeleteCommand="DELETE FROM [tblEmployee] WHERE [EmployeeId] = @original_EmployeeId"
When Optimistic Concurrency is not enabled, ConflictDetection property is set to "OverwriteChanges".
So, when optimistic concurrency option is used, and when we try to delete or update a row thru gridview control, then all the columns of the row that is being deleted are compared to check if the data has changed since the row was loaded into the gridview control. If data has changed, the row will not be deleted, and the gridview control simply refreshes with new data.
Now let us associate "SqlDataSource1" control with "GridView1" control
1. Right click on "GridView1" control and select "Show Smart Tag"
2. Select "SqlDataSource1" from "Choose Data Source" dropdownlist
3. Select "Enable Deleting" checkbox. At this point "Delete" button should appear on the gridview control.
Run the application. Click "Delete" button. The row gets deleted as expected.
Now execute the following SQL statement to update "Name" from "John" to "Johny" for employee with EmployeeId=2
Update tblemployee set Name='Johny' where EmployeeId = 2
At this point in the gridview control, row with EmployeeId=2, still shows the name as "John". Now, click Delete button in this row. Notice that, the row is not deleted and the grid gets refreshed with new data. This is because, we are using optmistic concurrency option and the data for this row has changed in the database table, after it was loaded into the gridview control.
If the row data has changed, and when that row is not deleted, then I want to display a message in a label control stating - "Employee Row with EmployeeID = 2 is not deleted due to data conflict"
To achieve this, we can use "RowDeleted" event of the gridview control. This event is raised after a row is deleted from the gridview control. Now let's generate the event handler method for "RowDeleted" event.
1. Right click on the gridview control and select "Properties"
2. In the "Properties" window click on events button
3. Double click on RowDeleted event. This should generate the event handler method in the code-behind file. Copy and paste the code from my blog from the following link.
http://csharp-video-tutorials.blogspo...
Run the application. After the data is loaded into gridview control, update any row in the database table, and try to delete that, same row in the gridview control. You should get the data conflict message as expected.
asp.net core docker ConflictDetection property of SqlDataSource control - Part 14 | |
56 Likes | 56 Dislikes |
21,947 views views | 524K followers |
Education | Upload TimePublished on 4 Mar 2013 |
Related keywords
wcf vs web api,ado.net core,sql server management studio,webkinz,webadvisor,craigslist nj,wcf one piece,asp.net core 3,ajax players,weber grill parts,webtoon,tutorials by hugo,csharp corner,mvc design pattern,asp.net machine account,servers for minecraft,asp.net core dependency injection,ado.net tutorial,services angular,ajax ontario,asp.net mvc tutorial,asp.net cos'è,csharp assembly,tutorialspoint python,sql join,services briefcase,asp.net core web api,ajax jquery,wccftech,craigslist ny,asp.net zero,csharp foreach,server memes,sql date format,services online,chase,serverless architecture,server resume,wcf c#,server books,tutorialspoint javascript,mvcc connect,ado.net mysql,services technologies gps,ajax deadpool,server jobs,cvs,website,mvc tutorial,costco hours,wcf service application,tutorialspoint spring,serverless,wcf soap,wcf cat,cool math games,wcf test client,services & training hse colombia sas,servicestack,citibank,asp.net core identity,sql union,ajax parking,sql database,asp.net core logging,mvconnect,cunyfirst,asp.net guida,wcf nba,csharp download,wcfi foundation,csharp online,wcf authentication,tutorials near me,http://asp.net,server 2019,chernobyl,ado.net descargar,web of dreams,serverminer,ajax cleaner,ado.net visual studio 2019,webassign,ado.net vs entity framework,ado.net visual studio 2017,csharp list,sql like,asp.net mvc,asp.net core tutorial,sqlite,wcfm,ajax roster,mvc architecture,http://ado.net,asp.net core mvc,ajax soccer,server hosting,wcfi,ajax dish soap,capital one,server rack,tutorialspoint html,csharp interface,craigslist,webroot,tutorialspoint reactjs,ajax request,wcf dragon ball,asp.net core 2.2,tutorialspoint python 3,sql developer,webster,services transmission company sas,sql group by,asp.net core signalr,services manager,mvc framework,ajax paving,mvc near me,tutorialspoint spring boot,mvc map,csharp online compiler,asp.net download,sql between,ado.net c# pdf,services tag dell,wcf 2019 nba,csharp switch,ado.net ventajas y desventajas,csharpstar,wcf tutorial,tutorialspoint,ajax meaning,csharp-video-tutorials.blogspot,tutorials dojo,central park 5,csharp string format,ado.net c#,asp.net core github,server status,ajax fc,server jobs nyc,asp.net core swagger,sql formatter,credit karma,services group,server error in '/' application,services windows,asp.net core 3.0,sql injection,tutorialspoint c#,wcf ria services,calculator,ado.net entity data model,sql insert,tutorialspoint tableau,services google play apk,sqlyog,asp.net core 3 release date,sql server,server job description,tutorials by a,servicenow,webcam,mvc hours,webmd symptom,csharp array,csharp enum,ajax call,asp.net core 2. guida completa per lo sviluppatore,asp.net core,server pro,server status ffxiv,cheap flights,webcrims,asp.net core hosting,services sas,tutorialspoint java,tutorialspoint java compiler,webmd,csharp to json,college football,ado.net dataset,csharp dictionary,cnn,website builder,tutorialspoint sql,asp.net web api,server side rendering,weber grills,sql server 2017,tutorialspoint spark,mvc nj,ado.net oracle,asp.net core download,csharp to vb.net,webster bank,webstaurant,tutorialsystems,ajax post,services fms publish announcement,services.msc no abre,ajax jersey,csharp operator,asp.net core razor pages,server duties,asp.net core environment variables,csharp random,century 21,services consultores,services consulting,mvcsd,services.msc,mvcsc,ado.net pdf,asp.net core configuration,ajax marvel,sql update,asp.net tutorial,mvc medical,ado.net entity data model visual studio 2019,wcfs international curriculum,mvc2,ado.net entity data model visual studio 2017,chase online,wcf api,costco,server jobs near me,webex,sql meaning,sql tutorial,sql commands,ado.net entity framework,ajax tavern,tutorialsteacher,ajax javascript,services desk,ajax greek,csharp tutorial,mvc pattern,ado.net sql server,ado.net connection,asp.net identity,mvcu,asp.net core middleware,wcf web service,mvc webadvisor,web store,mvcc,webmail,mvci,mvctc,
Không có nhận xét nào:
Đăng nhận xét