English 中文(简体)
文本箱 Won t Update Database
原标题:Textbox Won t Update Database

我可以拿我的文本箱更新数据库。 这些变化如所节省(这些变化在网页上得到拯救),而模式的流行则消失,但我试图改变数据库的案文保持不变。

Protected Sub SubmitEdit_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim myControl As Control = FindControl("txtData")
    If (Not myControl Is Nothing) Then
        Dim UpdateSql As String = "UPDATE Picklist SET (Data) = @Data WHERE PicklistID = @PicklistID"
        Using cn As New SqlConnection
        (System.Configuration.ConfigurationManager.ConnectionStrings
        ("LocalSqlServer").ConnectionString)
            Using sqlcmd As New SqlCommand(UpdateSql, cn)
                sqlcmd.Parameters.Add(New SqlParameter("@Data", myControl))
                cn.Open()
                sqlcmd.ExecuteNonQuery()
            End Using
        End Using
    Else
    End If
End Sub


 <asp:TabPanel ID="tab2"  runat="server" HeaderText="Descriptions">
<HeaderTemplate>Descriptions</HeaderTemplate>
    <ContentTemplate>
        <ul class="info">
        <asp:ListView ID="lvDescriptions" runat="server" 
          DataSourceID="dsAdminMarketingDescriptions" DataKeyNames="MarketingID">

        <ItemTemplate>
            <li class="item">
                <asp:LinkButton ID="ViewDescriptionButton" runat="server">
                <%# Eval("Title")%>
                </asp:LinkButton>

               <asp:ImageButton ID="DeleteDescriptionButton" runat="server"  
                Style="float:right;" AlternateText="" 
                ImageUrl="../../images/delete.png" CommandName="Delete" 
                OnClientClick="return confirm( Are you sure you want to delete this 
                description? )" />

                <asp:Panel ID="ViewDescriptionPanel" runat="server"
                  CssClass="DescModalPopup">                                   
                <div class="PopupHeader">View Description -- <%#Eval("Title") %>
                <asp:ImageButton ID="CancelDescriptionButton" runat="server" 
                  ImageUrl="../../images/cancel.png" AlternateText="" 
                  Style="float:right;"/>
                 <asp:ImageButton ID="EditDescriptionButton" runat="server" 
                   ImageUrl="../../images/edit.png" AlternateText="" 
                   Style="float:right;" CommandName="Edit" AutoPostBack="false" />
                </div>

                    <asp:Label ID="Description" runat="server" style="padding:2px;">
                    <%# Eval("Data")%>
                    </asp:Label>
                </asp:Panel> 

                <asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server" 
                  BackgroundCssClass="modalBackground" DropShadow="false" 
                  DynamicServicePath="" Enabled="true" 
                  PopupControlID="ViewDescriptionPanel" 
                  TargetControlID="ViewDescriptionButton" 
                  CancelControlID="CancelDescriptionButton"></asp:ModalPopupExtender> 


                <asp:Panel ID="EditDescriptionPanel" runat="server" 
                  CssClass="DescModalPopup">

                <div class="PopupHeader">Edit Description -- <%# Eval("Title")%>
                <asp:ImageButton ID="Cancel" runat="server" 
                  ImageUrl="../../images/cancel.png" AlternateText="" 
                  Style="float:right;"/>
                </div>

                    <asp:TextBox ID="txtData" runat="server" TextMode="MultiLine" 
                     Text= <%# Eval("Data")%> >
                    </asp:TextBox><br />
                <asp:Button ID="SubmitEdit" runat="server" Text="Submit" />
                <asp:Button ID="CancelEdit" runat="server" Text="Cancel" />
                </asp:Panel>

                <asp:ModalPopupExtender ID="EditDescriptionModal" runat="server" 
                BackgroundCssClass="modalBackground" DropShadow="false" 
                DynamicServicePath="" Enabled="true" 
                PopupControlID="EditDescriptionPanel" 
                TargetControlID="EditDescriptionButton">
                </asp:ModalPopupExtender>            
            </li>
        </ItemTemplate>

www.un.org/Depts/DGACM/index_spanish.htm UPDATE:我尝试利用一种试图捕获物来获取错误信息,但它的确做了一些工作。

Protected Sub SubmitEdit_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim myControl As Control = FindControl("txtData")
    If (Not myControl Is Nothing) Then
        Try
            Dim UpdateSql As String = "UPDATE Picklist 
                                       SET (Data) = @Data 
                                       WHERE Title = @Title"
            Using cn As New SqlConnection
             (System.Configuration.ConfigurationManager.ConnectionStrings
             ("LocalSqlServer").ConnectionString)
                Using sqlcmd As New SqlCommand(UpdateSql, cn)
                    sqlcmd.Parameters.Add(New SqlParameter("@Data", 
                     DirectCast(myControl, TextBox).Text))
                    cn.Open()
                    sqlcmd.ExecuteNonQuery()
                End Using
                cn.Close()
            End Using
        Catch ex As Exception
            Response.Write(ex.Message())
        End Try
    Else
    End If
    Response.Redirect(Request.RawUrl)
End Sub

www.un.org/Depts/DGACM/index_spanish.htm 最新资料:数字不详。 在这里,所有其他法典都保留同样的。

Protected Sub SubmitEdit_Click(ByVal sender As Object, ByVal e As EventArgs)
    For Each item As ListViewDataItem In lvDescriptions.Items
        Dim txtData As TextBox = DirectCast(item.FindControl("txtData"), TextBox)
        Dim ltlTitle As Literal = DirectCast(item.FindControl("ltlTitle"), Literal)
        Dim UpdateSql As String = "UPDATE Picklist 
                                   SET Data = @Data 
                                   WHERE Title = @Title"
        Using cn As New SqlConnection
        (System.Configuration.ConfigurationManager.ConnectionStrings
        ("LocalSqlServer").ConnectionString)
            Using sqlcmd As New SqlCommand(UpdateSql, cn)
                sqlcmd.Parameters.Add(New SqlParameter("@Data", txtData.Text))
                sqlcmd.Parameters.Add(New SqlParameter("@Title", ltlTitle.Text))

                cn.Open()
                sqlcmd.ExecuteNonQuery()

            End Using
            cn.Close()
        End Using
    Next
    Response.Redirect(Request.RawUrl)
End Sub
最佳回答

你们需要改变以下路线:

sqlcmd.Parameters.Add(New SqlParameter("@Data", myControl))

纽约总部

sqlcmd.Parameters.Add(New SqlParameter("@Data", myControl.Text))

<>Update:

Since the textbox is in a listview itemtemplate, you also need 纽约总部 change how it is discovered by looking at the currently selected list item. To do this, change the following line:

Dim myControl As Control = FindControl("txtData")

纽约总部:

Dim myControl As TextBox = DirectCast(lvDescriptions.Items(lvDescriptions.SelectedIndex).FindControl("txtData"), TextBox)

I have also updated the sqlParameters assignment 纽约总部 remove the DirectCast since we are now declaring the control as a TextBox (but it still needs 纽约总部 be updated 纽约总部 use the Text property from the original code).

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签