Question

I have a gridview with the following SqlDataSource:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnString%>" 
            SelectCommand="SELECT IDC, DESCPREVIEW, ADESCPREVIEW, DESC, ADESC, DATETOs, Active, HAVEIMG FROM CONTENT ORDER BY IDC DESC "
            UpdateCommand="[SP_UPDATE_CONTENT]" 
            UpdateCommandType="StoredProcedure">
            <UpdateParameters>
                <asp:Parameter Name="IDC" Type="Int32" />
               <asp:Parameter Name="DESCPREVIEW" Type="String" />
                <asp:Parameter Name="DESC" Type="String" />
                <asp:Parameter Name="DATETOs" Type="String" />
                <asp:Parameter Name="active" Type="Boolean" />
            </UpdateParameters>
</asp:SqlDataSource>

The Stored procedure has these parameters defined:

alter PROCEDURE [dbo].[SP_UPDATE_CONTENT]

@IDC AS INT,
@DESCPREVIEW AS NVARCHAR(800),
@DESC  AS NVARCHAR(1500),
@DATETOs AS VARCHAR(10),
@active as bit

I am getting the following error on Update:

[SqlException (0x80131904): Procedure or function SP_UPDATE_CONTENT has too many arguments specified.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1753346
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5295154
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +242
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +269
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +1325
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +175
   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +205
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +160
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +380
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +670
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +87
   System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1210
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +738
   System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +89
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +88
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +156
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9643314
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Although these are the same exact parameters

What could be going wrong here?

Was it helpful?

Solution

Problem Solved.

Apparently the Update Command considered all the Selected fields in the SelectCommand as parameters.

So I minimized the selectCommand to the needed number of fields only.

 SelectCommand="SELECT IDC, DESCPREVIEW, DESC, DATETOs, Active FROM CONTENT ORDER BY IDC DESC "
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top