Click here to Skip to main content
15,890,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,
i am having trouble with this problem from last week.
The problem gets more trickier bcoz when I try to insert record it shows this error"Procedure or Function 'Nav_Bulletins_Insert' expects parameter '@Bulletin', which was not supplied." but in DB the value is stored!

PLease solve this asap.
Stored Procedure looks like this:-

A
SQL
LTER procedure [dbo].[Nav_Bulletins_Insert]
(
@Bulletin nvarchar(500),
@Url nvarchar(200),
@IsActive bit
)
as
declare @DisplayId int
declare @Count int
declare @PostedDate nvarchar(100)

select @Count=count(*) from Nav_Bulletins
set @DisplayId=@Count+1
set @PostedDate = getdate()

insert into Nav_Bulletins(Bulletin,Url,IsActive,PostedDate,Dis playId)
values(@Bulletin, @Url, @IsActive, @PostedDate, @DisplayId)

C# code:-
C#
public void Nav_InsertBulletins()
{
DBManager.ExecuteNonQuery("Nav_Bulletins_Insert", _str_Bulletin, _str_Url, _Is_Active);
}

DB MANAGER.cs:
public static int ExecuteNonQuery(string spName, params object[] parameterValues)
{

SqlParameter[] commandParameters = null;

if (parameterValues != null & parameterValues.Length > 0)
{

commandParameters = GetParametersSetFromSp(spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteNonQuery(CommandType.StoredProcedure, spName, commandParameters);
}
else
{
return ExecuteNonQuery(CommandType.StoredProcedure, spName);
}
} //ExecuteNonQuery

public static int ExecuteNonQuery(CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
//create & open a SqlConnection, and dispose of it after we are done.
SqlConnection cn = new SqlConnection(_connectionString);
try
{
cn.Open();
return ExecuteNonQuery(cn, commandType, commandText, commandParameters);
}
finally
{
cn.Close();
cn.Dispose();
}
} //ExecuteNonQuery

public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
int retval = 0;

PrepareCommand(cmd, connection, commandType, commandText, commandParameters);

retval = cmd.ExecuteNonQuery(); error points here

cmd.Parameters.Clear();

return retval;

} //ExecuteNonQuery
Posted
Updated 14-Oct-11 23:10pm
v4

set @PostedDate = getdate()

here

set @PostedDate =(select getdate())
 
Share this answer
 
Somewhere, you code must supply a parameter to the stored procedure called (as if you couldn't guess) "@Bulletin"

Since you don't show us where any of the parameters are specified, we can't really comment on the specifics of the problem, so we have to go with general advice.

Put a break point on the line:
C#
retval = cmd.ExecuteNonQuery(); error points here
and look back through to see what parameters you are specifying - that should help you to identify where you need to add the code for the @Bulletin parameter.
 
Share this answer
 
Comments
07navneet 15-Oct-11 6:11am    
After putting brk point:-

+cmd {System.Data.SqlClient.SqlCommand}
-commandParameters {System.Data.SqlClient.SqlParameter[3]}
+[0] {@Bulletin} System.Data.SqlClient.SqlParameter
+[1] {@Url} System.Data.SqlClient.SqlParameter
+[2] {@IsActive} System.Data.SqlClient.SqlParameter
commandText "Nav_Bulletins_Insert" string
commandType StoredProcedure System.Data.CommandType
+connection {System.Data.SqlClient.SqlConnection}
retval 0 int
OriginalGriff 15-Oct-11 7:30am    
And what value has the parameter? Have you passed it a dbnull?
07navneet 15-Oct-11 7:54am    
no it was not passed null.
Bala Selvanayagam 15-Oct-11 8:25am    
Please check the connection string and make sure you are conncted to the right database perhaps ?
07navneet 15-Oct-11 12:07pm    
i hv cnctd to right DB thats why insertion of records is taking place in DB but error is coming just after inserting record.
This can happen, if you supply a NULL value for the parameter @Bulletin. Please check your parameter @Bulletin value.

try something

C#
if (a == null)
     a = "";



or

Alter procedure [dbo].[Nav]
                        
(
@Bulletin varchar(500)=null,
@Url nvarchar(200),
@IsActive bit
)
 
Share this answer
 
v3
Comments
07navneet 15-Oct-11 12:05pm    
if i make it null then permanently it stores value as NULL in table...
in procedure i had written exec <procedure name=""> at last line!! pointed by
thatraja
 
Share this answer
 
v2

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



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