| | |
problem with soft delete
![]() |
•
•
Join Date: May 2007
Posts: 4
Reputation:
Solved Threads: 0
Hi all,
I have a field named 'UserDeleted' which is set to false by default. Records shouldnt be deleted from the database but the field Userdeleted should be set to true when user deletes a particular record.
when i click on delete button a gridview is shown with delete commanfield and other details. If i press this delte button then the data gets delted from the databse, which i dnt want. instead whenever i select a row the Userdeleted field should be set to true and a message should be displayed tht the user is deleted.
Thanks in advance.
I have a field named 'UserDeleted' which is set to false by default. Records shouldnt be deleted from the database but the field Userdeleted should be set to true when user deletes a particular record.
when i click on delete button a gridview is shown with delete commanfield and other details. If i press this delte button then the data gets delted from the databse, which i dnt want. instead whenever i select a row the Userdeleted field should be set to true and a message should be displayed tht the user is deleted.
Thanks in advance.
again. I am not to clear about what exactly you are saying. But if you create a DataGrid it usually create its won functions for Add, Update and Delete (the DataGrid CRUD methods). you can do one of 2 things:
1. remove the ability to delete using the datagrid controls
2. edit the control methods themselves to do what you want them to do.
If that was your problem I hope it helps. But usually if you post code it makes things alot easier to help you out with your problem.
8-D
1. remove the ability to delete using the datagrid controls
2. edit the control methods themselves to do what you want them to do.
If that was your problem I hope it helps. But usually if you post code it makes things alot easier to help you out with your problem.
8-D
- mike mclennan
•
•
Join Date: May 2007
Posts: 4
Reputation:
Solved Threads: 0
Hi mike..
Am using visual web developer 2005 express and sql server management studio express for developing an intranet application.
u r rite datagrid creates itz own add,update and delete functions.
Whenever a user selects a row in the datagrid, then that should be logically deleted. .i.e. UserDeleted field in the database should be set to 'true' which was 'false' by default before.
Hope u got it what i want to tell..
Code goes here:
<asp:Content ID="Content1" ContentPlaceHolderID="conthld" Runat="Server">
<asp:GridView ID="GridView1" runat="server" style="z-index: 101; left: 218px; position: absolute; top: 224px" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="LoginId" DataSourceID="SqlDataSource1" GridLines="Vertical" OnSelectedIndexChanging="select_click" >
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<Columns>
<asp:CommandField SelectText="Delete" ShowSelectButton="True" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="LoginId" HeaderText="LoginId" ReadOnly="True" SortExpression="LoginId" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="MobileNo" HeaderText="MobileNo" SortExpression="MobileNo" />
<asp:BoundField DataField="UserAccess" HeaderText="UserAccess" SortExpression="UserAccess" />
</Columns>
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="Gainsboro" />
</asp:GridView>
<asp
qlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cashflow %>"
SelectCommand="SELECT UserName, LoginId, Email, MobileNo, UserAccess FROM Login_Tab WHERE (UserDeleted = 'False')" UpdateCommand="UPDATE Login_Tab SET UserDeleted = 'False' WHERE (LoginId = LoginId)">
</asp
qlDataSource>
</asp:Content>
<script runat=server >
Dim constr As String
Dim cmd As SqlCommand
Dim con As SqlConnection
Dim sql As String
Dim re As SqlDataReader
Protected Sub select_click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs)
sql = "update Login_Tab set UserDeleted='True' where LoginId= @LoginId "
Try
con = New SqlConnection(constr)
cmd = New SqlCommand(sql, con)
con.Open()
cmd.ExecuteNonQuery()
lblinfo.Visible = True
lblinfo.Text = "Record Deleted"
Catch ex As Exception
lblinfo.Visible = True
lblinfo.Text = ex.Message
Finally
con.Close()
End Try
End Sub
</script>
May be the problem seems small, but am ignorant about the code.
The query tht is highlighted with red color is giving problem i think.
Thanks a lot for the reply.
Please let me know where i have gone wrong.
Am using visual web developer 2005 express and sql server management studio express for developing an intranet application.
u r rite datagrid creates itz own add,update and delete functions.
Whenever a user selects a row in the datagrid, then that should be logically deleted. .i.e. UserDeleted field in the database should be set to 'true' which was 'false' by default before.
Hope u got it what i want to tell..
Code goes here:
<asp:Content ID="Content1" ContentPlaceHolderID="conthld" Runat="Server">
<asp:GridView ID="GridView1" runat="server" style="z-index: 101; left: 218px; position: absolute; top: 224px" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="LoginId" DataSourceID="SqlDataSource1" GridLines="Vertical" OnSelectedIndexChanging="select_click" >
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<Columns>
<asp:CommandField SelectText="Delete" ShowSelectButton="True" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="LoginId" HeaderText="LoginId" ReadOnly="True" SortExpression="LoginId" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="MobileNo" HeaderText="MobileNo" SortExpression="MobileNo" />
<asp:BoundField DataField="UserAccess" HeaderText="UserAccess" SortExpression="UserAccess" />
</Columns>
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="Gainsboro" />
</asp:GridView>
<asp
qlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cashflow %>"SelectCommand="SELECT UserName, LoginId, Email, MobileNo, UserAccess FROM Login_Tab WHERE (UserDeleted = 'False')" UpdateCommand="UPDATE Login_Tab SET UserDeleted = 'False' WHERE (LoginId = LoginId)">
</asp
qlDataSource></asp:Content>
<script runat=server >
Dim constr As String
Dim cmd As SqlCommand
Dim con As SqlConnection
Dim sql As String
Dim re As SqlDataReader
Protected Sub select_click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs)
sql = "update Login_Tab set UserDeleted='True' where LoginId= @LoginId "
Try
con = New SqlConnection(constr)
cmd = New SqlCommand(sql, con)
con.Open()
cmd.ExecuteNonQuery()
lblinfo.Visible = True
lblinfo.Text = "Record Deleted"
Catch ex As Exception
lblinfo.Visible = True
lblinfo.Text = ex.Message
Finally
con.Close()
End Try
End Sub
</script>
May be the problem seems small, but am ignorant about the code.
The query tht is highlighted with red color is giving problem i think.
Thanks a lot for the reply.
Please let me know where i have gone wrong.
I am still not 100% on what you are trying to do. sorry I am really trying to understand but i found something that caught my eye. Maybe it will help
If you notice you have 2 update commands which are doing the opposite of each other, one is setting the value to true, the other is setting the value to false. Maybe that is what it is suppose to do, but it does not seem to fit. Hope this helps.
SelectCommand="SELECT UserName, LoginId, Email, MobileNo, UserAccess FROM Login_Tab WHERE (UserDeleted = 'False')" UpdateCommand="UPDATE Login_Tab SET UserDeleted = 'False' WHERE (LoginId = LoginId)"> </asp: sqlDataSource> </asp:Content> <script runat=server > Dim constr As String Dim cmd As SqlCommand Dim con As SqlConnection Dim sql As String Dim re As SqlDataReader Protected Sub select_click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) sql = "update Login_Tab set UserDeleted='True' where LoginId= @LoginId "
If you notice you have 2 update commands which are doing the opposite of each other, one is setting the value to true, the other is setting the value to false. Maybe that is what it is suppose to do, but it does not seem to fit. Hope this helps.
- mike mclennan
![]() |
Similar Threads
- Problem when adding delete confirmation (ASP)
- Internet Explorer multiple windows problem - XP (Web Browsers)
- more problem!!!! (Windows Software)
- Trojan Problem - Hijackthis log posted (Viruses, Spyware and other Nasties)
- i cannot delete any junkmail in my hotmail (Web Browsers)
- dubble delete (C++)
Other Threads in the ASP.NET Forum
- Previous Thread: help Web server Crashes
- Next Thread: Login page refreshes and clears fields
Views: 2154 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.aspx .net .net-security-trust 2.0 3.5 2008 access activexcontrol ajax appliances asp asp.net asp.net-mvc authentication bc30451 blog box browser businesslogiclayer button c# chat checkbox click commonfunctions connectionstring control countryselector database datagrid datagridview datalist deployment development dgv dialog dom dropdownmenu dynamic edit editing email feedback flash form form-auth-subdomain forms formview ftp googlemaps gridview iframe iis image impersonation javascript learn-asp.net linq-sql list login migration mssql mtom navigation novell object opener opera pocketpc problem profile programmer redirect refresh remember-me rotatepage running search select server service session silverlight simple smtp-asp.net sql sql-server tracking translate update validation vb.net video vista visualstudio web webarchitecture webcam website xml





