I have a page with 3 grids, and 3 ObjectDataSources - one for each grid. They all work great, except for the last grid on the page, the Select method works fine, but it will not fire the Update Method. The obvious argument signature, parameter problems
etc... are not occuring, and there are no error messages - it just does not get to the Update Method. The StoredProc that is being called from the UpdateMethod code behind is fine, it used in other places.
If your SP is right, I think the problem may happen where you only dynamically add Parameters instead of assigning values to these parameters.
So please change your codes like this following:
Public Sub UpdateRCCA(ByVal ID As Integer,
ByVal Problem As String, ByVal RootCause As String, ByVal CloseDate As String) As String
Dim conn As New SqlConnection(ConnectionString)
Dim cmd As New SqlCommand("sp_smcUpdSigInfo", conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@ID", ID))
cmd.Parameters.Add(New SqlParameter("@Problem", Problem))
cmd.Parameters.Add(New SqlParameter("@RootCause", RootCause))
cmd.Parameters.Add(New SqlParameter("@CloseDate", CloseDate))
conn.Open()
cmd.ExecuteNonQuery()
End Sub
Remove try……Catch and see whether there's anything wrong with that.
SteveAP
0 Points
2 Posts
ObjectDataSource not firing Update Method
Jan 07, 2013 06:58 PM|LINK
I have a page with 3 grids, and 3 ObjectDataSources - one for each grid. They all work great, except for the last grid on the page, the Select method works fine, but it will not fire the Update Method. The obvious argument signature, parameter problems etc... are not occuring, and there are no error messages - it just does not get to the Update Method. The StoredProc that is being called from the UpdateMethod code behind is fine, it used in other places.
<asp:panel ID = "pnlRCCA" runat="server" Visible = "true" > <asp:GridView ID="gvwRCCA" runat="server" AutoGenerateColumns="False" ShowFooter="True" CellPadding="4" DataSourceID="oRCCA" DataKeyNames="ID" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" > <Columns> <asp:TemplateField ItemStyle-BackColor="White" HeaderStyle-BackColor="#D3D3D3"> <ItemTemplate> <asp:label ID="Label1" runat="server" text='<%# Eval("Program") %>' forecolor= "SteelBlue" font-bold="True" font-italic="True" font-size="Large" style="text-align:center;"></asp:label> <p>Supplier Name : <asp:label ID="lHeader" runat="server" Text='<%# Eval("SupplierName") %>' ForeColor="Maroon" Font-Bold="True" Font-Italic="True" /> </p> <asp:Button ID="btnEdit" CommandName="Edit" Text="Edit" Font-Size="8pt" Width="45px" Runat="Server"/> <asp:Label ID="lbID" runat="server" Text='<%# Eval("ID") %>' Visible="false" /> <table id = "tblRCCA"> <tr class= "tblHeader"> <td class="adjacent">Responsible</td> <td class="adjacent">Cause Code</td> <td class="adjacent">Cause Location</td> <td class="adjacent">BORIS Number</td> <td class="adjacent">Days On Report</td> </tr> <tr > <td class="sigadjacent"><%# Eval("Responsible")%> <td class="sigadjacent"><%# Eval("CauseCode")%> </td> <td class="sigadjacent"><%# Eval("CauseLocation")%> </td> <td class="sigadjacent"><%# Eval("BORISNumber")%> </td> <td class="sigadjacent"><%# Eval("DaysOnReport")%> </td> </tr> </table> <p> </p> <table> <tr class= "tblHeader"> <td class="adjacent" >Problem</td> <td class="adjacent">Root Cause</td> </tr> <tr > <td class="sigadjacent"><%# Eval("Problem")%> </td> <td class="sigadjacent"><%# Eval("RootCause")%> </td> </tr> </table> <p></p> </ItemTemplate> <ItemStyle VerticalAlign="Top" HorizontalAlign = "Left" /> <EditItemTemplate> <asp:Button ID="btnUpdate" CommandName="Update" Text="Update" Font-Size="8pt" Width="48px" Runat="Server"/> <asp:Button ID="btnCancel" CommandName="Cancel" Text="Cancel" Font-Size="8pt" Width="48px" Runat="Server"/> <table border="1" > <tr> <td align="right"> Close Date: </td> <td colspan="5"> <asp:TextBox ID="datepicker" Text='<%# Bind("CloseDate") %>' runat="server" ClientIDMode="Static" /> </td> </tr> <tr> <th>Problem</th> <th>Root Cause</th> <tr> <td> <Custom:CustomEditor ID="myEdit" CssClass="textWidth" runat="server" Content='<%# Bind("Problem") %>' /> </td> <td> <Custom:CustomEditor ID="CustomEditor1" CssClass="textWidth" runat="server" Content='<%# Bind("RootCause") %>' /> </td> </tr> </table> <table> <tr> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </asp:panel><asp:ObjectDataSource ID="oRCCA" runat="server" TypeName="GetAccessData" SelectMethod="GetRCCADetail" UpdateMethod="UpdateRCCA"> <SelectParameters> <asp:SessionParameter Name="cat" SessionField="Category" DefaultValue="RCCA" Type="String" /> <asp:SessionParameter Name="Prog" SessionField="Program" Type="String" DefaultValue="%" /> <asp:SessionParameter Name="status" SessionField="Status" Type="String" DefaultValue="%" /> <asp:SessionParameter Name="comm" SessionField="Commodity" Type="String" DefaultValue="%" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="ID" Type="Int32" /> <asp:Parameter Name="Problem" Type="String" /> <asp:Parameter Name="RootCause" Type="String" /> <asp:Parameter Name="CloseDate" Type="String" /> </UpdateParameters> </asp:ObjectDataSource> Public Function UpdateRCCA(ByVal ID As Integer, ByVal Problem As String, ByVal RootCause As String, ByVal CloseDate As String) As String Dim conn As New SqlConnection(ConnectionString) Dim cmd As New SqlCommand("sp_smcUpdSigInfo", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add(New SqlParameter("@ID", ID)) cmd.Parameters.Add(New SqlParameter("@Problem", Problem)) cmd.Parameters.Add(New SqlParameter("@RootCause", RootCause)) cmd.Parameters.Add(New SqlParameter("@CloseDate", CloseDate)) conn.Open() Dim msg As String = "" Try ExecuteNonQuery(cmd) msg = "Update Succeeded!" Catch ex As Exception msg = ex.Message Finally End Try Return msg End FunctionDecker Dong ...
All-Star
118619 Points
18779 Posts
Re: ObjectDataSource not firing Update Method
Jan 08, 2013 08:04 AM|LINK
Hi,
If your SP is right, I think the problem may happen where you only dynamically add Parameters instead of assigning values to these parameters.
So please change your codes like this following:
Public Sub UpdateRCCA(ByVal ID As Integer, ByVal Problem As String, ByVal RootCause As String, ByVal CloseDate As String) As String Dim conn As New SqlConnection(ConnectionString) Dim cmd As New SqlCommand("sp_smcUpdSigInfo", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add(New SqlParameter("@ID", ID)) cmd.Parameters.Add(New SqlParameter("@Problem", Problem)) cmd.Parameters.Add(New SqlParameter("@RootCause", RootCause)) cmd.Parameters.Add(New SqlParameter("@CloseDate", CloseDate)) conn.Open() cmd.ExecuteNonQuery() End SubRemove try……Catch and see whether there's anything wrong with that.