Click here to Skip to main content
15,917,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm using store procedure to take the record from table...with C#

What I have tried:

Sql Store procedure
<pre lang="SQL">ALTER PROCEDURE  [dbo].[USP_Check_If_EmSalary_Is_proveded_OrNot]
(
@EmId		Nvarchar(150),
@StartDate	datetime,
@EndDate    datetime
)
AS
BEGIN
	SELECT *  
  FROM [dbo].[Empoly_Salary]
  where [EmId] = @EmId and [StartDatee]= @StartDate  or [EnDate] =  @EndDate
END

My C# Code is Here
C#
<pre>        private bool ISSaveFirstTime()
        {
            DataTable dt = new DataTable();
            using (SqlConnection conn4 = new SqlConnection(DbConfigClass.connectDb()))
            {
                conn4.Open();
                using (SqlCommand cmd = new SqlCommand("USP_Check_If_EmSalary_Is_proveded_OrNot", conn4))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@EmId", EmIdlabel.Text );
                    cmd.Parameters.AddWithValue("@StartDate", StartDatedateTimePicker.Value.Date);
                    cmd.Parameters.AddWithValue("@EndDate", EndDatedateTimePicker.Value.Date);
                    SqlDataReader drd = cmd.ExecuteReader();
                    dt.Load(drd);
                }
                if (dt.Rows.Count >= 0)
                {

                    //MessageBoxClass.ShowInformationgMessage("Row exisist","");
                    return false;

                }                
            }
            return true;
        }
Posted
Updated 17-Mar-18 14:09pm
Comments
Maciej Los 18-Mar-18 16:50pm    
Not clear! Please, provide more details. Sample data and expected output might be helpful.

1 solution

Use this where clause:

WHERE [EmId] = @EmId AND CONVERT(DATE,[StartDate])= CONVERT(DATE,@StartDate) AND CONVERT(DATE,[EnDate]) = CONVERT(DATE,@EndDate)


When sql compares datetime objects, it includes the time component. I'm pretty sure you're only interested in comparing the date component, so you actually have to convert the compared datetimes to dates.
 
Share this answer
 
v2
Comments
Fahid Zahoor 17-Mar-18 23:52pm    
But i need these Records where EmName is Same And any one Date is Same Just Like Any one date is same from StartDate and EndDate.
#realJSOP 18-Mar-18 7:37am    
Dude, I have no idea what you're asking for. Find someone that speaks better English to help you re-phrase your question.

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