S
Shardev2020
Guest
Hi developpers;
I am using a stored procedure I wrote for a SQL localDB database. It works fine when executed from sever explorer.
When using it from a C# function, I get the foolowing Error:
System.Data.SqlClient.SqlException: 'Procedure or function 'PR_ADDBENEFICIARYTYPE' expects parameter '@BenefTypeName', which was not supplied.'
Databse table definition
CREATE TABLE [dbo].[BeneficiaryType] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[BenefTypeName] NVARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
Stored procedure
CREATE PROCEDURE PR_ADDBENEFICIARYTYPE
@BenefTypeName varchar(50)
AS
INSERT INTO [dbo].[BeneficiaryType]
([BenefTypeName] )
VALUES
(@BenefTypeName )
C# code
public void Excute(string store, SqlParameter[] pr)
{
command.Parameters.Clear();
command.Connection = con;
command.CommandText = store;
command.CommandType = CommandType.StoredProcedure;
if (pr != null)
{
command.Parameters.AddRange(pr);
}
command.ExecuteNonQuery();
}
public void AddBeneficiaryType(string BenefTypeName)
{
DAL.Open();
DataTable dt = new DataTable();
SqlParameter[] pr = new SqlParameter[1];
pr[0] = new SqlParameter(@BenefTypeName, SqlDbType.NVarChar);
pr[0].Value = BenefTypeName;
DAL.Excute("PR_ADDBENEFICIARYTYPE", pr);
DAL.Close();
}
I am stuck. I tried many solution but I did not sole the problem.
Continue reading...
I am using a stored procedure I wrote for a SQL localDB database. It works fine when executed from sever explorer.
When using it from a C# function, I get the foolowing Error:
System.Data.SqlClient.SqlException: 'Procedure or function 'PR_ADDBENEFICIARYTYPE' expects parameter '@BenefTypeName', which was not supplied.'
Databse table definition
CREATE TABLE [dbo].[BeneficiaryType] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[BenefTypeName] NVARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
Stored procedure
CREATE PROCEDURE PR_ADDBENEFICIARYTYPE
@BenefTypeName varchar(50)
AS
INSERT INTO [dbo].[BeneficiaryType]
([BenefTypeName] )
VALUES
(@BenefTypeName )
C# code
public void Excute(string store, SqlParameter[] pr)
{
command.Parameters.Clear();
command.Connection = con;
command.CommandText = store;
command.CommandType = CommandType.StoredProcedure;
if (pr != null)
{
command.Parameters.AddRange(pr);
}
command.ExecuteNonQuery();
}
public void AddBeneficiaryType(string BenefTypeName)
{
DAL.Open();
DataTable dt = new DataTable();
SqlParameter[] pr = new SqlParameter[1];
pr[0] = new SqlParameter(@BenefTypeName, SqlDbType.NVarChar);
pr[0].Value = BenefTypeName;
DAL.Excute("PR_ADDBENEFICIARYTYPE", pr);
DAL.Close();
}
I am stuck. I tried many solution but I did not sole the problem.
Continue reading...