User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 427,499 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,456 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 6683 | Replies: 0
Reply
Join Date: Jan 2006
Posts: 14
Reputation: Texpert is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Texpert's Avatar
Texpert Texpert is offline Offline
Newbie Poster

Help Problem Updating Row in GridView

  #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
============================================
    <asp:GridView ID="GridView2" runat="server" AllowSorting="True" AutoGenerateColumns="False"
        DataKeyNames="RegID" DataSourceID="SqlDataSource2" Style="z-index: 102; left: 453px;
        position: absolute; top: 305px">
        <Columns>
            <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/icon-pencil-x.gif"
                DeleteImageUrl="~/Images/icon-delete.gif" EditImageUrl="~/Images/icon-pencil.gif"
                ShowDeleteButton="True" ShowEditButton="True" UpdateImageUrl="~/Images/icon-floppy.gif" />
            <asp:BoundField DataField="RegID" HeaderText="RegID" InsertVisible="True" ReadOnly="True"
                SortExpression="RegID" Visible="False" />
            <asp:BoundField DataField="STU_ID" HeaderText="STU_ID" SortExpression="STU_ID" Visible="False" />
            <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
            <asp:BoundField DataField="Branch_ID" HeaderText="Branch_ID" SortExpression="Branch_ID"
                Visible="False" />
            <asp:BoundField DataField="Branch_Name" HeaderText="Branch_Name" SortExpression="Branch_Name" />
            <asp:BoundField DataField="AcademicYear_ID" HeaderText="AcademicYear_ID" SortExpression="AcademicYear_ID"
                Visible="False" />
            <asp:BoundField DataField="Academic_Year" HeaderText="Academic_Year" SortExpression="Academic_Year" />
            <asp:BoundField DataField="Registration_Type" HeaderText="Registration_Type" SortExpression="Registration_Type" />
            <asp:BoundField DataField="regdate" HeaderText="regdate" ReadOnly="True" SortExpression="regdate" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:KPLCOneSourceConnectionString %>"
        OldValuesParameterFormatString="original_{0}" DeleteCommand="DELETE FROM Registration WHERE (RegID = @Original_RegID)"
        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)">
        <DeleteParameters>
            <asp:Parameter Name="Original_RegID" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Branch_ID" />
            <asp:Parameter Name="AcademicYear_ID" />
            <asp:Parameter Name="Registration_Type" />
            <asp:Parameter Name="Registration_Date" />
            <asp:Parameter Name="original_RegID" />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="vStudent_ID" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
==================================
select statement in Store Proc is
SELECT RegID,
Registration.Student_ID as STU_ID,
Last_Name + ' ' + First_Name as Name,
Registration.Branch_ID,
Branch_Name,Registration.AcademicYear_ID,
Academic_Year,
Registration_Type,
ISNULL(CONVERT(nvarchar(11),Registartion_Date , 109),' / / ') as regdate,
Registration.UpdatedBy,
ISNULL(CONVERT(nvarchar(11),Registration.UpdatedDate , 109),' / / ') as EnterDate
from Registration
INNER JOIN Student on Registration.Student_ID = student.Student_ID
INNER JOIN Branch on Registration.Branch_ID = Branch.Branch_ID
INNER JOIN Academic_Year on Registration.AcademicYear_ID = Academic_Year.Academic_YearID
Where Registration.Student_ID = @vStudent_ID
ORDER BY regdate
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 7:07 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC