Click here to Skip to main content
16,022,896 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I am trying to add "dayid" details in my store procedure getting thins error like Procedure or function 'SP_PROSER_Timesheetnew_ADD' expects parameter '@DayId', which was not supplied.

After written store procedure in above way i just added few lines of code in my page.

Code:
protected void AddTimesheet(GridViewRow gvrow, int clientID, int statusid, int j)
  {
    int i = 0;
    string[] BH = new string[7];
    string[] NBH = new string[7];

    BH[0] = ((TextBox)gvrow.FindControl("txtSun" + j + "B")).Text;
    BH[1] = ((TextBox)gvrow.FindControl("txtMon" + j + "B")).Text;
    BH[2] = ((TextBox)gvrow.FindControl("txtTue" + j + "B")).Text;
    BH[3] = ((TextBox)gvrow.FindControl("txtWed" + j + "B")).Text;
    BH[4] = ((TextBox)gvrow.FindControl("txtThu" + j + "B")).Text;
    BH[5] = ((TextBox)gvrow.FindControl("txtFri" + j + "B")).Text;
    BH[6] = ((TextBox)gvrow.FindControl("txtSat" + j + "B")).Text;

    NBH[0] = ((TextBox)gvrow.FindControl("txtSun" + j + "N")).Text;
    NBH[1] = ((TextBox)gvrow.FindControl("txtMon" + j + "N")).Text;
    NBH[2] = ((TextBox)gvrow.FindControl("txtTue" + j + "N")).Text;
    NBH[3] = ((TextBox)gvrow.FindControl("txtWed" + j + "N")).Text;
    NBH[4] = ((TextBox)gvrow.FindControl("txtThu" + j + "N")).Text;
    NBH[5] = ((TextBox)gvrow.FindControl("txtFri" + j + "N")).Text;
    NBH[6] = ((TextBox)gvrow.FindControl("txtSat" + j + "N")).Text;
    string date = txtFrom.Text;
    System.DateTime mydate = new System.DateTime();
    mydate = DateTime.Parse(date);
    string[] dates = new string[7];
    string[] DayId = new string[8];
    for (i = 0; i < 7; i++)
    {
    dates[i] = mydate.AddDays(i).ToString("MM/dd/yyyy");
    con.Open();
    cmd = new SqlCommand("SP_PROSER_Timesheetnew_ADD", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@Date", dates[i]);
    cmd.Parameters.AddWithValue("@ConsultantID", ddlConsultant.SelectedItem.Value);
    cmd.Parameters.AddWithValue("@CompanyID", ddlCompany.SelectedItem.Value);
    cmd.Parameters.AddWithValue("@ContractId", clientID);
    cmd.Parameters.AddWithValue("@Comment", txtComment.Text);
    cmd.Parameters.AddWithValue("@Hours", BH[i]);
    cmd.Parameters.AddWithValue("@IsBillable", 1);
    cmd.Parameters.AddWithValue("@TSFrom", txtFrom.Text);
    cmd.Parameters.AddWithValue("@TSTo", txtTo.Text);
    cmd.Parameters.AddWithValue("@StatusId", statusid);
    cmd.Parameters.AddWithValue("@DayId", DayId[i+1]);
    cmd.ExecuteNonQuery();
    con.Close();

    }
    for (i = 0; i < 7; i++)
    {
    dates[i] = mydate.AddDays(i).ToString("MM/dd/yyyy");
    con.Open();
    cmd = new SqlCommand("SP_PROSER_Timesheetnew_ADD", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@Date", dates[i]);
    cmd.Parameters.AddWithValue("@ConsultantID", ddlConsultant.SelectedItem.Value);
    cmd.Parameters.AddWithValue("@CompanyID", ddlCompany.SelectedItem.Value);
    cmd.Parameters.AddWithValue("@ContractId", clientID);
    cmd.Parameters.AddWithValue("@Comment", txtComment.Text);
    cmd.Parameters.AddWithValue("@IsBillable", 0);
    cmd.Parameters.AddWithValue("@Hours", NBH[i]);
    cmd.Parameters.AddWithValue("@TSFrom", txtFrom.Text);
    cmd.Parameters.AddWithValue("@TSTo", txtTo.Text);
    cmd.Parameters.AddWithValue("@StatusId", statusid);
    cmd.Parameters.AddWithValue("@DayId", DayId[i+1]);
    cmd.ExecuteNonQuery();
    con.Close();
    }

  }


My storeprocedure :

USE [prosercorp]
GO
/****** Object:  StoredProcedure [dbo].[SP_PROSER_Timesheetnew_ADD]    Script Date: 01/23/2012 16:28:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[SP_PROSER_Timesheetnew_ADD]      
@TSFrom date,
@TSTo date,
@ContractId int,
@IsBillable bit,
@ConsultantID int,
@CompanyID int,
@Hours varchar(5),
@Comment varchar(500),
@Date date,
@DayId int,
@StatusId int   
AS
IF NOT EXISTS(SELECT TSMasterId FROM TBL_PROSER_TIMESHEETMASTER WHERE TSFrom=@TSFrom AND TSTo=@TSTo AND STATUS=1)    
 BEGIN      
  declare @TSMasterId int    
INSERT INTO TBL_PROSER_TIMESHEETMASTER      
    (TSFrom ,
    TSTo,
    status)      
VALUES   (@TSFrom,
    @TSTo, 1)      
select  @TSMasterId=@@IDENTITY
end
else
begin
declare @AttachmentID int
select @TSMasterId=TSMasterId from TBL_PROSER_TIMESHEETMASTER where TSFrom=@TSFrom and TSTo=@TSTo and Status=1
select @AttachmentID=AttachmentId from TBL_PROSER_ATTACHMENTSNEW where TSMasterId=@TSMasterId and ConsultantId=@ConsultantId and  CompanyId=@ContractId and IsBillable=@IsBillable and Status=1
 end
 declare @x int       
/*select @x=COUNT(Hours) from TBL_PROSER_TIMESHEETNEW where TSMasterId=@TSMasterId and ConsultantID=@ConsultantId and ContractId=@ContractId and Status=1
if(@x>=14)
begin       
  update TBL_PROSER_TIMESHEETNEW set
StatusId=@StatusId,
AttachmentID=@AttachmentID,
Hours=@Hours,
[Comment/Reason]=@Comment where
CompanyID=@CompanyID and
ConsultantID=@ConsultantID and
ContractId=@ContractId and
TSMasterId=@TSMasterId and
IsBillable=@IsBillable and
date=@Date and  Status=1    

end*/
if exists(select TimesheetId from TBL_PROSER_TIMESHEETNEW where TSMasterId=@TSMasterId and ConsultantID=@ConsultantId and CompanyID=@ContractId and IsBillable=@IsBillable and date=@Date and Status=1)

begin       
  update TBL_PROSER_TIMESHEETNEW set
StatusId=@StatusId,
AttachmentID=@AttachmentID,
Hours=@Hours,
[Comment/Reason]=@Comment where
OurCompanyID=@CompanyID and
ConsultantID=@ConsultantID and
CompanyID=@ContractId and
TSMasterId=@TSMasterId and
IsBillable=@IsBillable and

date=@Date and  Status=1
end
else
begin
insert into TBL_PROSER_TIMESHEETNEW (ConsultantID,
OurCompanyID,
CompanyID,
StatusId,
TSMasterId,
AttachmentID,
DayId,
Date,
Hours,
[Comment/Reason]
,IsBillable,
Status)values(@ConsultantID,
 @CompanyID,
 @ContractId,
 @StatusId,
  @TSMasterId,
  @AttachmentID,
  @DayId,
   @Date,
   @Hours,
    @Comment,
   @IsBillable,
   1)

 
 end



Please guide me.
Posted

Stored Procedure accept parameters in which they declared
so, write first

cmd.Parameters.AddWithValue("@DayId", DayId[i+1])

before cmd.Parameters.AddWithValue("@StatusId", statusid)
may be it will help???
 
Share this answer
 
v2
Comments
[no name] 23-Jan-12 23:01pm    
Hi,

I just added as u sad, but still same error.

protected void AddTimesheet(GridViewRow gvrow, int clientID, int statusid, int j)
{
int i = 0;
string[] BH = new string[7];
string[] NBH = new string[7];

BH[0] = ((TextBox)gvrow.FindControl("txtSun" + j + "B")).Text;
BH[1] = ((TextBox)gvrow.FindControl("txtMon" + j + "B")).Text;
BH[2] = ((TextBox)gvrow.FindControl("txtTue" + j + "B")).Text;
BH[3] = ((TextBox)gvrow.FindControl("txtWed" + j + "B")).Text;
BH[4] = ((TextBox)gvrow.FindControl("txtThu" + j + "B")).Text;
BH[5] = ((TextBox)gvrow.FindControl("txtFri" + j + "B")).Text;
BH[6] = ((TextBox)gvrow.FindControl("txtSat" + j + "B")).Text;

NBH[0] = ((TextBox)gvrow.FindControl("txtSun" + j + "N")).Text;
NBH[1] = ((TextBox)gvrow.FindControl("txtMon" + j + "N")).Text;
NBH[2] = ((TextBox)gvrow.FindControl("txtTue" + j + "N")).Text;
NBH[3] = ((TextBox)gvrow.FindControl("txtWed" + j + "N")).Text;
NBH[4] = ((TextBox)gvrow.FindControl("txtThu" + j + "N")).Text;
NBH[5] = ((TextBox)gvrow.FindControl("txtFri" + j + "N")).Text;
NBH[6] = ((TextBox)gvrow.FindControl("txtSat" + j + "N")).Text;
string date = txtFrom.Text;
System.DateTime mydate = new System.DateTime();
mydate = DateTime.Parse(date);
string[] dates = new string[7];
string[] DayId = new string[8];
for (i = 0; i < 7; i++)
{
dates[i] = mydate.AddDays(i).ToString("MM/dd/yyyy");
con.Open();
cmd = new SqlCommand("SP_PROSER_Timesheetnew_ADD", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Date", dates[i]);
cmd.Parameters.AddWithValue("@ConsultantID", ddlConsultant.SelectedItem.Value);
cmd.Parameters.AddWithValue("@CompanyID", ddlCompany.SelectedItem.Value);
cmd.Parameters.AddWithValue("@ContractId", clientID);
cmd.Parameters.AddWithValue("@Comment", txtComment.Text);
cmd.Parameters.AddWithValue("@Hours", BH[i]);
cmd.Parameters.AddWithValue("@IsBillable", 1);
cmd.Parameters.AddWithValue("@TSFrom", txtFrom.Text);
cmd.Parameters.AddWithValue("@TSTo", txtTo.Text);
cmd.Parameters.AddWithValue("@StatusId", statusid);
cmd.Parameters.AddWithValue("@DayId", DayId[i+1]);
cmd.ExecuteNonQuery();
con.Close();

}
for (i = 0; i < 7; i++)
{
dates[i] = mydate.AddDays(i).ToString("MM/dd/yyyy");
con.Open();
cmd = new SqlCommand("SP_PROSER_Timesheetnew_ADD", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Date", dates[i]);
cmd.Parameters.AddWithValue("@ConsultantID", ddlConsultant.SelectedItem.Value);
cmd.Parameters.AddWithValue("@CompanyID", ddlCompany.SelectedItem.Value);
cmd.Parameters.AddWithValue("@ContractId", clientID);
cmd.Parameters.AddWithValue("@Comment", txtComment.Text);
cmd.Parameters.AddWithValue("@IsBillable", 0);
cmd.Parameters.AddWithValue("@Hours", NBH[i]);
cmd.Parameters.AddWithValue("@TSFrom", txtFrom.Text);
cmd.Parameters.AddWithValue("@TSTo", txtTo.Text);

cmd.ExecuteNonQuery();
con.Close();
}
[no name] 23-Jan-12 23:31pm    
My problem is solved.Values are storing in db
DayId[i + 1] = i + 1;
Check No. of Parameters of Store Procedure and cmd.Parameters.
Both should be same.
 
Share this answer
 
My problem is solved.Values are storing in db DayId[i + 1] = i + 1;
 
Share this answer
 
<pre>My problem is solved.Values are storing in db.

int[] DayId = new int[8];
DayId[i + 1] = i + 1;</pre>
 
Share this answer
 

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