记录不在详细信息视图中更新 [英] Record not updating in detailsview

查看:84
本文介绍了记录不在详细信息视图中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用asp.net中的detailsview更新数据库记录。我使用下面的代码运行良好,但最后没有记录更新我不知道为什么记录没有更新,因为没有错误,因为我知道代码如下:

 <   asp:DetailsView     ID   =  DetailsView1     runat   = 服务器    CellPadding   =  4    ForeColor   = #333333    GridLines   =   

宽度 = 100% DataSourceID = SqlDataSource1 AllowPaging = True AutoGenerateRows = False DataKeyNames = QuestionID

AutoGenerateDeleteButton = True AutoGenerateEditButton = True

AutoGenerateInsertButton = True DefaultMode = 修改 >
< FooterStyle BackColor = #5D7B9D 字体粗体 < span class =code-keyword> = True ForeColor = 白色 / >
< CommandRowStyle BackColor = #E2DED6 Font-Bold = True / >
< EditRowStyle BackColor = #999999 / >
< RowStyle < span class =code-attribute> BackColor = #F7F6F3 ForeColor = #333333 / >
< PagerStyle BackColor = #284775 ForeColor = 白色 Horizo​​ntalAlign = 中心 / >
< FieldHeaderStyle BackColor = #E9ECF1 字体粗体 = < span class =code-keyword> True
/ >
< HeaderStyle BackColor = #5D7B9D 字体粗体 = True ForeColor < span class =code-keyword> = 白色 / >
< AlternatingRowStyle BackColor = 白色 ForeColor = #284775 / >
< 字段 >
< asp:TemplateField HeaderText = QuestionID > ;
& lt; ItemTemplate >
<% #Eval( QuestionID%>
< / ItemTemplate >
< / asp:TemplateField >
< asp:BoundField DataField = Questiontext HeaderText = Questiontext / >
< asp:BoundField DataField = Helptext HeaderText = 帮助文本 / < span class =code-keyword>>

< asp:BoundField DataField = Answertype HeaderText = Answertype / >

< / Fields >
< / asp:DetailsView >

< asp:SqlDataSource < span class =code-attribute> ID = SqlDataSource1 runat = server ConnectionString =' < ;% $ ConnectionStrings:ConnectionString %> '

SelectCommand = 选择* FROM问题WHERE SurveyId = @sid

< span class =code-attribute> DeleteCommand = 删除FROM问题WHERE QuestionID = @QID

UpdateCommand = 更新问题SET Questiontext = @text,Helptext = @htext,Answertype = @atype WHERE QuestionID = @QID

>
< DeleteParameters >
< asp:参数 名称 = QID 类型 = Int32 < span class =code-keyword> / >
< / DeleteParameters >
< UpdateParameters >
< asp:参数 名称 = QID 类型 = Int32 / < span class =code-keyword>>
< asp:参数 名称 = text 类型 = string / >
< asp:参数 名称 = htext 类型 = string / >
< asp:参数 < span class =code-attribute>名称 = atype Ty pe = string / >

< / UpdateParameters >
< SelectParameters >
< asp:QueryStringParameter 名称 = sid QueryStringField = SurveyId / >
< / SelectParameters >
< / asp:SqlDataSource >



对不起,如果有一些愚蠢的错误类型我不知道我在这个领域仍然是一个更加轻松!

解决方案

ConnectionStrings:ConnectionString %> '

SelectCommand = 选择* FROM问题WHERE SurveyId = @ sid

< span class =code-attribute> DeleteCommand = 删除FROM问题WHERE QuestionID = @QID

UpdateCommand = UPDATE Questions SET Questiontext = @text,Helptext = @htext,Answertype = @atype WHERE QuestionID = @QID

>
< DeleteParameters >
< asp:参数 名称 = QID 类型 = Int32 / >
< / DeleteParameters >
< UpdateParameters >
< asp:参数 名称 = QID < span class =code-attribute>类型 = Int32 / >
< asp:参数 名称 = text 类型 = string / >
< asp:参数 名称 < span class =code-keyword> =
htext Type = string / >
< asp:参数 名称 = atype 类型 = string / >

< / UpdateParameters >
< SelectParameters >
< asp:QueryStringParameter 名称 = sid QueryStringField = SurveyId / >
< / SelectParameters > ;
< / asp:SqlDataSource >



很抱歉,如果有一些愚蠢的错误,我不知道,因为我仍然是这个领域的一个更加轻松!


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:

<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!

解决方案

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!


这篇关于记录不在详细信息视图中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆