Click here to Skip to main content
15,917,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Procedure or Function expects parameter '@Regdate'(datatpe-datetime),which was not supply


What I have tried:

ALTER PROCEDURE [dbo].[sp_InsertLabreg] 
(
@patfor varchar(100)= null ,
        @LABID varchar(100)=null,
        @pattypr varchar(100)= null ,
        @Regdate datetime,

)
AS
BEGIN
INSERT INTO labreg
	(   patfor,
		LABID,
        pattypr,
        Regdate)
)
INSERT INTO labreg
	(   patfor,
		LABID,
        pattypr,
        Regdate) End
Posted
Updated 27-Feb-20 3:06am
Comments
Richard MacCutchan 20-Apr-19 4:09am    
As the message states ...

Look at the code where you call the procedure: your first three parameters are marked as defaulting to NULL, which means if you don't provide a value, it defaults OK.
But @Regdate has no default, which means that if you don't supply it you will get an error.
You could add "= NULL" to the defintion, but ... that allows you to send completely blank rows to your DB ... which probably isn't a good idea.
 
Share this answer
 
The two most common issues in calling an SP from C# are:

The first is not passing in required parameters, as OriginalGriff states in the other answer.

The second is failing to set the SqlCommand.CommandType in which case it will default to Text.
C#
using (SqlConnection conn = new SqlConnection(connectionString)) {
  using (SqlCommand cmd = new SqlCommand({ProcedureName}, conn)) {
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@ParameterName", ParameterValue);
    // and so on
   }
}
SqlCommand.CommandType Property (System.Data.SqlClient) | Microsoft Docs[^]
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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