Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to update records of database using detailsview in asp.net . i have used the following code it runs well but at the end no record is updated i am not aware of the reason that why record is not updated as there is no error as for as i know code is as follow:
XML
<asp:DetailsView ID="DetailsView1" runat="Server" CellPadding="4" ForeColor="#333333" GridLines="None"
     Width="100%" DataSourceID="SqlDataSource1" AllowPaging="True" AutoGenerateRows="False" DataKeyNames="QuestionID"
     AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
                    AutoGenerateInsertButton="True" DefaultMode="Edit" >
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <EditRowStyle BackColor="#999999" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Fields>
            <asp:TemplateField HeaderText="QuestionID">
                <ItemTemplate>
                    <%# Eval("QuestionID") %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Questiontext" HeaderText="Questiontext" />
            <asp:BoundField DataField="Helptext" HeaderText="Helptext" />
            <asp:BoundField DataField="Answertype" HeaderText="Answertype" />

        </Fields>
    </asp:DetailsView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString %>'
       SelectCommand="Select * FROM Questions WHERE SurveyId=@sid"
       DeleteCommand="Delete FROM Questions WHERE QuestionID = @QID"
       UpdateCommand="UPDATE Questions SET Questiontext = @text, Helptext = @htext, Answertype = @atype WHERE QuestionID = @QID"
   >
        <DeleteParameters>
            <asp:Parameter Name="QID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="QID" Type="Int32" />
            <asp:Parameter Name="text" Type="string"  />
            <asp:Parameter Name="htext" Type="string" />
            <asp:Parameter Name="atype"  Type="string" />

         </UpdateParameters>
        <SelectParameters>
         <asp:QueryStringParameter  Name="sid" QueryStringField="SurveyId"/>
       </SelectParameters>
        </asp:SqlDataSource>

Sorry if there is some stupid type of error which i dont know as i am still a laerner in this field!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900