Thursday, March 8, 2012

Adding parameters during .updating event handler

Not receiving any errors. The update runs perfectly on all fields, except for the added parameter during the sub. I need to change the hidden field's value after parsing out several fields in the form and generating a logfile entry of sorts. This needs to happen after all the form fields are updated, but before the update is executed.

aspx: (relevant parts only...)
<asp:SqlDataSourceID="TicketDetails"runat="server"ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
UpdateCommand="UPDATE Tickets SET TicketSuspense = @.TicketSuspense, TicketPriority = @.TicketPriority, TicketLastUpdated = CURRENT_TIMESTAMP, TicketStatus = 'Assigned', TicketTechnicianNotes = @.TicketTechnicianNotes WHERE (TicketID = @.TicketID)">
<UpdateParameters>
<asp:ParameterName="TicketPriority"Type="String"/>
<asp:ParameterName="TicketSuspense"Type="DateTime"/>
<asp:ParameterName="TicketID"Type="Int32"/>
</UpdateParameters>
</asp:SqlDataSource>

codebehind: (once again, the relevant parts only)
ProtectedSub TicketDetails_Updating(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)Handles TicketDetails.Updating
TicketTechnicianNotesHiddenField.Value ="some text..."& TicketTechnicianNotesHiddenField.Value
TicketDetails.UpdateParameters.Add(New Parameter("TicketTechnicianNotes", TypeCode.String, TicketTechnicianNotesHiddenField.Value))
EndSub

Thanks,

- Brad

What about this:

ProtectedSub TicketDetails_Updating(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)Handles TicketDetails.Updating
TicketTechnicianNotesHiddenField.Value ="some text..."& TicketTechnicianNotesHiddenField.Value

e.Command.Parameters("@.TicketTechnicianNotes").Value = TicketTechnicianNotesHiddenField.Value


EndSub

|||

I think that was the only variation I hadn't yet tried. It worked.

I have to ask... what caused the "Add" not to work?

Thanks,

- Brad

|||

"TheSqlDataSource control will also automatically create parameters based on values passed by a data-bound control... "

You can find more information from this link:

http://msdn2.microsoft.com/en-us/library/z72eefad.aspx

No comments:

Post a Comment