My Source is below code problem
SqlCommand cmd = new SqlCommand("SP_OverTime_Details_1", new SqlConnection(ConfigurationManager.AppSettings["connectionString"]));
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@In_UserID", gvStaffDetails.SelectedRow.Cells[2].Text.ToString().Trim());
cmd.Parameters.AddWithValue("@In_Month", Session["paymonth"].ToString().Trim());
cmd.Parameters.AddWithValue("@In_Year", Session["payyear"].ToString().Trim());
cmd.Connection.Open();
cmd.ExecuteNonQuery();
dr = cmd.ExecuteReader();
while (dr.Read())
{
lbltotalovertime.Text = dr["@totalovertime"].ToString();
}
cmd.Connection.Close();
I am using Above source but not reterived storeprocedure data this my problem, how to solve this problem
My Store Procedure:
Craete procedure [dbo].[SP_OverTime_Details_1]
(
@In_UserID int,
@In_Month char(10),
@In_Year int,
@overtime time(7) output
)
AS
begin
DECLARE @total_sec INT
--DECLARE @totalovertime time(7)
begin tran
DECLARE @getOverTime CURSOR
SET @getOverTime = CURSOR FOR
SELECT total_sec = SUM(( DATEPART(hh, Overtime_HHMM) * 3600 ) +
( DATEPART(mi, Overtime_HHMM) * 60 ) +
DATEPART(ss, Overtime_HHMM))
FROM Accounts_DailyAttendance
where UserID=1046 and datename(month,processdate) = 'May' and datepart(yyyy,processdate)= 2014 and Overtime_HHMM<>'00:00:00.0000000'
OPEN @getOverTime
FETCH NEXT
FROM @getOverTime INTO @total_sec
WHILE @@FETCH_STATUS = 0
BEGIN
--print @total_sec
SELECT @overtime = CONVERT(TIME, DATEADD(s, @total_sec, 0))
FROM Accounts_DailyAttendance
--print @totalovertime
FETCH NEXT
FROM @getOverTime INTO @total_sec
END
commit tran
CLOSE @getOverTime
DEALLOCATE @getOverTime
END
Thanks
Loading

Riddhi ValechaPosted Oct 21, 2014, 5:05 AM
SqlConnection(ConfigurationManager.AppSettings["connectionString"]));
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@In_UserID", gvStaffDetails.SelectedRow.Cells[2].Text.ToString().Trim());
cmd.Parameters.AddWithValue("@In_Month", Session["paymonth"].ToString().Trim());
cmd.Parameters.AddWithValue("@In_Year", Session["payyear"].ToString().Trim());
cmd.Connection.Open();
cmd.ExecuteNonQuery();
dr = cmd.ExecuteReader();
while (dr.Read())
{
lbltotalovertime.Text = dr["@totalovertime"].ToString();
}
cmd.Connection.Close();
---
Issue-1. SQLCommand will take query and connection objects as arguments. Instead, use simple SQLCommand object.
Issue-2. You cannot use ExecuteNonQuery and ExecuteReader in the same method. Use only one of them.
Since the stored procedure will return only DateTime, make the return type as DateTime or String.
--------
E.g.-
Assume that objects are declared and connection is open.
string outputdata = string.empty;
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SP_STOREDPROCEDURENAME";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Variable1", "abc");
table = new DataTable();
adp = new SqlDataAdapter();
cmd.ExecuteNonQuery();
adp.SelectCommand = cmd;
adp.Fill(table);
if (table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
outputdata = dr["ColumnName"].ToString();
}
return username;
}
else return null;
--
Call this function in aspx.cs page.
Hope this helps.