Hi all.
I have used a SqlDataSource in my page with this delete command:
DELETE FROM tblPersonnel WHERE (ID = @.original_ID)
and the "OldValueParameterFormatSring" property of the datasource is "original_{0}".
and i also have a GridView and a button for delete in rows.(it's CommandName is "Delete"). But when i try to delete a record, the record does not get deleted and this button only makes a PostBack on the page! Why doesn't it work?
Thanks in advance.
Check whether the grid's delete command event is triggered by debugging.
Also, check the parameter value that is passed
|||Yes. It is triggered. RowDeleting and Even RowDeleted but e.AffectedRows is 0.
|||Do you have DeleteParameter Original_ID:
|||<DeleteParameters>
<asp:Parameter Name="original_ID" Type="Int32" />
</DeleteParameters>
Monitor the parameter when deleteing, is it null?
|||Yes. I have DeleteParameter.
parameters for deleting are not null.
What incomprehensive error!
Can you post your code?
|||My codes are very long but the main code is here:
<asp:SqlDataSourceID="sdsPersonnel"runat="server"ConflictDetection="CompareAllValues"ConnectionString="<%$ ConnectionStrings:UniversityDBConnectionString %>"DeleteCommand="DELETE FROM tblPersonnel WHERE (ID = @.original_ID)"
InsertCommand="INSERT INTO tblPersonnel(Name, Family, NationalCode, IdentityCardNumber, FatherName, BirthDay, BirthPlace, IsMale, Marital, ServicePlace, EmploymentType, WorkBeginDate, Saved, Education, WorkingField, Duty, IntPhone, ExtPhone, Fax, Email, Image, Type, Culture) VALUES (@.Name, @.Family, @.NationalCode, @.IdentityCardNumber, @.FatherName, @.BirthDay, @.BirthPlace, @.IsMale, Marital, @.ServicePlace, @.EmploymentType, @.WorkBeginDate, @.Saved, @.Education, @.WorkingField, @.Duty, @.IntPhone, @.ExtPhone, @.Fax, @.Email, @.Image, 'AcademicUnit', @.Culture)"
OldValuesParameterFormatString="original_{0}"OnInserted="sdsPersonnel_Inserted"
SelectCommand="SELECT ID, Name, Family, NationalCode, IdentityCardNumber, FatherName, BirthDay, BirthPlace, IsMale, Marital, ServicePlace, EmploymentType, WorkBeginDate, Saved, Education, WorkingField, Duty, IntPhone, ExtPhone, Fax, Email, Image, Type, Culture FROM tblPersonnel WHERE (Type='AcademicUnit') AND (Culture=@.Culture)"
UpdateCommand="UPDATE tblPersonnel SET Name = @.Name, Family = @.Family, NationalCode = @.NationalCode, IdentityCardNumber = @.IdentityCardNumber, FatherName = @.FatherName, BirthDay = @.BirthDay, BirthPlace = @.BirthPlace, IsMale = @.IsMale, Marital=@.Marital, ServicePlace = @.ServicePlace, EmploymentType = @.EmploymentNumber, WorkBeginDate = @.WorkBeginDate, Saved = @.Saved, Education = @.Education, WorkingField = @.WorkingField, Duty = @.Duty, IntPhone = @.IntPhone, ExtPhone = @.ExtPhone, Fax = @.Fax, Email = @.Email WHERE (ID = @.original_ID)">
<DeleteParameters>
<asp:ParameterName="original_ID"Type="Int32"/>
</DeleteParameters>
</asp:SqlDataSource>
<asp:GridViewID="GridView2"runat="server"AutoGenerateColumns="False"DataSourceID="sdsPersonnel"
Width="100%"OnRowDeleted="GridView2_RowDeleted"OnRowDeleting="GridView2_RowDeleting">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ButtonID="btnDeletePersonnel"runat="server"CommandArgument='<%# Eval("Image") %>'
CommandName="Delete"CausesValidation="false"OnCommand="btnDeletePersonnel_Command"
Text="<%$ Resources:Resource, Delete %>"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protectedvoid btnDeletePersonnel_Command(object sender,CommandEventArgs e)
{
FileInfo fi =newFileInfo(Server.MapPath("~/Upload/Images/Personnels/" + e.CommandArgument.ToString()));
if (fi.Exists)
fi.Delete();
}
I tried to use your code with my database values and everything works like it should. Can you post yourGridView2_RowDeleting andGridView2_RowDeleted events?
No comments:
Post a Comment