Converted from SqlDataSource to ObjectDataSource, causing grief
I have created a data access layer in my web app which uses ObjectDataSource instead of SqlDataSource. I have a FormView to update some data in my database. In my old asp.net code I had something like:
<asp:SqlDataSource ID="sdsTradeDetails" runat="server"
ConnectionString="<%$ ConnectionStrings:ForexDB %>"
SelectCommand="usp_GetTrade" SelectCommandType="StoredProcedure"
UpdateCommand="usp_UpdateTrade" UpdateCommandType="StoredProcedure"
<SelectParameters>
<asp:ControlParameter Name="tradeId" ControlID="grdTrades" PropertyName="SelectedDataKey.Value" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter Name="tradeId" ControlId="frmTrade" PropertyName="SelectedValue" />
</UpdateParameters>
</asp:SqlDataSource>
Which worked fine. I have replaced the SqlDataSource with this:
<asp:ObjectDataSource
id="srcTrade"
TypeName="DatabaseComponent.DBUtil"
SelectMethod="GetTrade"
UpdateMethod="UpdateTrade"
runat="server">
<SelectParameters>
<asp:QueryStringParameter Name="tradeId" QueryStringField="tradeId" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter Name="tradeId" ControlId="frmTrade" PropertyName="SelectedValue" 开发者_StackOverflow社区/>
</UpdateParameters>
</asp:ObjectDataSource>
But now I get this error when I click the Update button in my FormView:
Exception Details: System.InvalidOperationException: ObjectDataSource 'srcTrade' could not find a non-generic method 'UpdateTrade' that has parameters: symbol, pctAccountRisked, tradeSetupId, lotsPerUnit, initialStopPrice, tfCode, MAEPips, MFEPips, tradeGrade, executionGrade, tradeTypeId, comment, tradeId.
In my DBUtil class I have this for UpdateTrade:
public void UpdateTrade(
int tradeId,
string symbol,
decimal pctAccountRisked,
string tradeSetupId,
decimal lotsPerUnit,
decimal initialStopPrice,
string tfCode,
int MAEPips,
int MFEPips,
int tradeGrade,
int executionGrade,
string comment)
{
SqlCommand cmd = new SqlCommand("usp_UpdateTrade");
cmd.Parameters.AddWithValue("@tradeId", tradeId);
cmd.Parameters.AddWithValue("@symbol", symbol);
cmd.Parameters.AddWithValue("@pctAccountRisked", pctAccountRisked);
cmd.Parameters.AddWithValue("@tradeSetupId", tradeSetupId);
cmd.Parameters.AddWithValue("@lotsPerUnit", lotsPerUnit);
cmd.Parameters.AddWithValue("@initialStopPrice", initialStopPrice);
cmd.Parameters.AddWithValue("@tfCode", tfCode);
cmd.Parameters.AddWithValue("@MAEPips", MAEPips);
cmd.Parameters.AddWithValue("@MFEPips", MFEPips);
cmd.Parameters.AddWithValue("@tradeGrade", tradeGrade);
cmd.Parameters.AddWithValue("@executionGrade", executionGrade);
cmd.Parameters.AddWithValue("@comment", comment);
UpdateTable(cmd, "trade");
}
and this for GetTrade:
public DataTable GetTrade(int tradeId)
{
SqlCommand cmd = new SqlCommand("usp_GetTrade");
cmd.Parameters.AddWithValue("@tradeId", tradeId);
return FillDataTable(cmd, "trade");
}
Please help!
Hi your UpdateTrade method and the passing parameters from your datasource are missmatching. please recheck them
精彩评论