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
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
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.