Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
THIS IS MY TABLE CODE

CREATE TABLE [dbo].[LupHolidays](
[HolidaysId] [int] IDENTITY(1,1) NOT NULL,
[HolidaysDetails] [nvarchar](250) NULL,
[HolidaysDate] [datetime] NULL,
[IsMandetory] [bit] NULL,
[DateEntered] [datetime] NULL,
[EnteredByID] [int] NULL,
[DateUpdated] [datetime] NULL,
[UpdatedByID] [int] NULL,
[UpdatedBy] [nvarchar](250) NULL,
[IsActive] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[HolidaysId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

THIS IS MY PROCEDURE CODE

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddEditLupHoliday]
@holidaysdetails nvarchar(250),
@holidaysdate datetime,
@ismandetory bit,
@dateenterd datetime,
@enteredbyid int,
@dateupdated datetime,
@updatedbyid int,
@updatedby nvarchar(250),
@isactive bit
AS
INSERT INTO LupHolidays(HolidaysDetails, HolidaysDate, IsMandetory, DateEntered, EnteredByID, DateUpdated, UpdatedByID, UpdatedBy, IsActive)

VALUES(@holidaysdetails, @holidaysdate, @ismandetory, @dateenterd, @enteredbyid, @dateupdated, @updatedbyid, @updatedby, @isactive)


THIS IS MY C# CODE TO CALL SP

public void DAAddEditLupHoliday(eLupHoliday eLH, out string oHolidaysDetails)
{
try
{
DataSet ds = new DataSet();
DBAccess objDbAccess = new DBAccess();
string SP = "AddEditLupHoliday";

SqlParameter[] spc = new SqlParameter[9];
spc[1] = new SqlParameter("@holidaysdetails", eLH.HolidaysDetails);
spc[2] = new SqlParameter("@holidaysdate", eLH.HolidaysDate);
spc[3] = new SqlParameter("@ismandetory", eLH.IsMandetory);
spc[4] = new SqlParameter("@dateenterd", eLH.DateEntered);
spc[5] = new SqlParameter("@enteredbyid", eLH.EnteredByID);
spc[6] = new SqlParameter("@dateupdated", eLH.DateUpdated);
spc[7] = new SqlParameter("@updatedbyid", eLH.UpdatedByID);
spc[8] = new SqlParameter("@updatedby", eLH.UpdatedBy);
spc[9] = new SqlParameter("@isactive", eLH.IsActive);

ds = objDbAccess.getDataSet(SP, spc);
oHolidaysDetails = ds.Tables[0].Rows[1]["HolidaysDetails"].ToString();
}
catch (Exception ex)
{
throw;
}
}

What I have tried:

1. I droped the procedure and build it again.
2. Re-check every code which I created.
3. I changed the table and rows value in c# code.
4. Build parameters again in c# code and sql.
Posted
Updated 1-Aug-22 7:59am
Comments
0x01AA 1-Aug-22 14:57pm    
You assign parameter index 1...9 like spc[1] = .... Should this not more be from 0...8: spc[0] = ...; .... spc[8] = ...?
Tushar Paul 2-Aug-22 1:24am    
I have one more column name Id and I set autoincrement on it. So I didn't include it in insertion section.
So I start the column number from spc[1] to spc[9].
Richard Deeming 2-Aug-22 4:43am    
But you're still trying to set the 10th element in an array of 9 elements.

Remember, arrays in C# - like any decent language - are 0-based. An array of 9 elements has indices from 0 to 8.
0x01AA 2-Aug-22 6:22am    
Which ends usually in an exception or am I missing something?
Richard Deeming 2-Aug-22 6:27am    
It would. So either the code shown in the question isn't the code that's running, or the error shown in the question isn't the actual error.

1 solution

Use the debugger to see exactly what you are passing from eLH.HolidaysDetails to your SP. Chances are that it's a null value, which means that the parameter will have no value, and will not be passed to the SP as a result.
 
Share this answer
 
Comments
Tushar Paul 2-Aug-22 1:28am    
While passing the values, there is the data into the eLH.HolidaysDetails and I checked it carefully, it calls the sp, all fields ar filles with values. There is no problem, but I don't know why this error shown while inserting data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900