1

In a C# website application with a database, I set a gridView table so that I could edit the values in the table by row, but it appears that I need a stored procedure to do that.

Below is the stored procedure along with the errors I get when trying to use/run it. Please help.

CREATE PROCEDURE [dbo].[ProcedureGridView1_RowUpdated] 
    @Property_ID INT,
    @Type_ID INT,
    @Property_Name TEXT,
    @Address VARCHAR(MAX),
    @Coordinates NUMERIC(18, 0),
    @Property_Description TEXT,
    @Map IMAGE,
    @Landlord_ID INT,
    @BuildingSize INT,
    @Allowance MONEY,
    @Amenities TEXT,
    @Attachedfiles_ID INT,
    @UpdatedDate DATE,
    @ParkingRatio TEXT,
    @Expenses MONEY,
    @Stat INT
AS
    IF EXISTS (SELECT *
               FROM PROPERTY)
       SET NOCOUNT OFF;

    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON

    UPDATE [PROPERTY]
    SET [Property_ID] = @Property_ID,
        [Type_ID] = @Type_ID,
        [Property_Name] = @Property_Name,
        [Address] = @Address,
        [Coordinates] = @Coordinates,
        [Property_Descrption] = @Property_Description,
        [Map] = @Map,
        [Landlord_ID] = @Landlord_ID,
        [BuildingSize] = @BuildingsizE,
        [Allowance] = @AllowancE,
        [Amenities] = @Amenities,
        [AttachedFiles_ID] = @AttachedfileS_ID,
        [UpdatedDate] = @UpdatedDate,
        [ParkingRatio] = @ParkingRatio,
        [Expenses] = @Expenses,
        [Stat] = @Stat;

A test query using the procedure:

USE [C:\USERS\MydataBase.MDF]
GO

DECLARE @return_value Int

EXEC @return_value = [dbo].[ProcedureGridView1_RowUpdated] 
  @Property_ID = 4,
  @Type_ID = 4,
  @Property_Name = N'TEST',
  @Address = N'TEST',
  @Coordinates = 11,
  @Property_Description = N'TEST',
  @Map = NULL,
  @Landlord_ID = 1,
  @BuildingSize = 5000,
  @Allowance = 50,
  @Amenities = N'3',
  @Attachedfiles_ID = 1,
  @UpdatedDate = 10/15/2015,
  @ParkingRatio = N';35',
  @Expenses = 46,
  @Stat = 2

SELECT @return_value as 'Return Value'
GO

Errors when trying to run the stored procedure:

Server Error in '/' Application. Procedure or function ProcedureGridView1_RowUpdated has too many arguments specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Procedure or function ProcedureGridView1_RowUpdated has too many arguments specified.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): Procedure or function ProcedureGridView1_RowUpdated has too many arguments specified.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +2523746
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +81 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +609 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +3731 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +225 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2064 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +375
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +337 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +280 System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +392 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) +106 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) +877 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) +90 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) +161 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9748498 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1738

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.57.0

  • 2
    If you're passing in a date, it must be a string, and please use YYYYMMDD it works with all regional settings: @UpdatedDate = '20151015' – James Z Oct 17 '15 at 5:25
  • No sure if you intended so, but it's easy to assume all the set commands are inside the if but actually only the first one is -- but changing ansi_nulls based on row existence sounds something i really don't recommend doing – James Z Oct 17 '15 at 5:26
  • If you are using the built in updates in c# you need to map the columns in the data grid to the parameters in the stored procedure. If you have additional custom columns in the data grid the built-in update methods are going to map them and that probably what is causing the exception. You will need to manually map the data grid columns to the command parameters. MSDN Insert Command – Aaron Oct 17 '15 at 16:00
  • @UpdatedDate = '20151015' did not make a difference..............................Removed the if statement, but did not make a difference.....Will look into the Mapping – KES Oct 18 '15 at 14:52
  • 1
    ntext, text, and image data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. See details here – marc_s Oct 20 '15 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.