Problem Updating Row in GridView

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2006
Posts: 14
Reputation: Texpert is an unknown quantity at this point 
Solved Threads: 0
Texpert's Avatar
Texpert Texpert is offline Offline
Newbie Poster

Problem Updating Row in GridView

 
0
  #1
Sep 20th, 2006
Hi,

I am having problem with my Editable GridView. I am selecting columns from SQL-Server 2005 DB using a store procedure [with multiple tables in it] and then I wrote UPDATE and DELTE statements in the GridView query builder.

When I run the page, Select and delete works fine but while updating the row in database , it inserts all the NULLS for those columns whose values are not changed in the Grid.

Please see the attached code for review
============================================
  1. <asp:GridView ID="GridView2" runat="server" AllowSorting="True" AutoGenerateColumns="False"
  2. DataKeyNames="RegID" DataSourceID="SqlDataSource2" Style="z-index: 102; left: 453px;
  3. position: absolute; top: 305px">
  4. <Columns>
  5. <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/icon-pencil-x.gif"
  6. DeleteImageUrl="~/Images/icon-delete.gif" EditImageUrl="~/Images/icon-pencil.gif"
  7. ShowDeleteButton="True" ShowEditButton="True" UpdateImageUrl="~/Images/icon-floppy.gif" />
  8. <asp:BoundField DataField="RegID" HeaderText="RegID" InsertVisible="True" ReadOnly="True"
  9. SortExpression="RegID" Visible="False" />
  10. <asp:BoundField DataField="STU_ID" HeaderText="STU_ID" SortExpression="STU_ID" Visible="False" />
  11. <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
  12. <asp:BoundField DataField="Branch_ID" HeaderText="Branch_ID" SortExpression="Branch_ID"
  13. Visible="False" />
  14. <asp:BoundField DataField="Branch_Name" HeaderText="Branch_Name" SortExpression="Branch_Name" />
  15. <asp:BoundField DataField="AcademicYear_ID" HeaderText="AcademicYear_ID" SortExpression="AcademicYear_ID"
  16. Visible="False" />
  17. <asp:BoundField DataField="Academic_Year" HeaderText="Academic_Year" SortExpression="Academic_Year" />
  18. <asp:BoundField DataField="Registration_Type" HeaderText="Registration_Type" SortExpression="Registration_Type" />
  19. <asp:BoundField DataField="regdate" HeaderText="regdate" ReadOnly="True" SortExpression="regdate" />
  20. </Columns>
  21. </asp:GridView>
  22. <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:KPLCOneSourceConnectionString %>"
  23. OldValuesParameterFormatString="original_{0}" DeleteCommand="DELETE FROM Registration WHERE (RegID = @Original_RegID)"
  24. SelectCommand="GetRegDetails" SelectCommandType="StoredProcedure" UpdateCommand="UPDATE Registration SET Branch_ID = @Branch_ID, AcademicYear_ID = @AcademicYear_ID, Registration_Type = @Registration_Type, Registartion_Date = @Registration_Date WHERE (RegID = @original_RegID)">
  25. <DeleteParameters>
  26. <asp:Parameter Name="Original_RegID" />
  27. </DeleteParameters>
  28. <UpdateParameters>
  29. <asp:Parameter Name="Branch_ID" />
  30. <asp:Parameter Name="AcademicYear_ID" />
  31. <asp:Parameter Name="Registration_Type" />
  32. <asp:Parameter Name="Registration_Date" />
  33. <asp:Parameter Name="original_RegID" />
  34. </UpdateParameters>
  35. <SelectParameters>
  36. <asp:ControlParameter ControlID="GridView1" Name="vStudent_ID" PropertyName="SelectedValue"
  37. Type="Int32" />
  38. </SelectParameters>
  39. </asp:SqlDataSource>
==================================
select statement in Store Proc is
  1.  
  2. SELECT RegID,
  3. Registration.Student_ID as STU_ID,
  4. Last_Name + ' ' + First_Name as Name,
  5. Registration.Branch_ID,
  6. Branch_Name,Registration.AcademicYear_ID,
  7. Academic_Year,
  8. Registration_Type,
  9. ISNULL(CONVERT(nvarchar(11),Registartion_Date , 109),' / / ') as regdate,
  10. Registration.UpdatedBy,
  11. ISNULL(CONVERT(nvarchar(11),Registration.UpdatedDate , 109),' / / ') as EnterDate
  12. from Registration
  13. INNER JOIN Student on Registration.Student_ID = student.Student_ID
  14. INNER JOIN Branch on Registration.Branch_ID = Branch.Branch_ID
  15. INNER JOIN Academic_Year on Registration.AcademicYear_ID = Academic_Year.Academic_YearID
  16. Where Registration.Student_ID = @vStudent_ID
  17. ORDER BY regdate
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC