Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I am unable to remove this error also i don't know why i am facing these error.
My code block is:
dt.OpenCon();

        SqlCommand cmd = new SqlCommand();

        cmd.Parameters.AddWithValue("@DAY", DateTime.Today.Day);
        cmd.Parameters.AddWithValue("@Month", DateTime.Today.Month);
        
        string str = "SELECT MA_First_Name,MA_Email_Id FROM Master_Applicant WHERE DATEPART(DAY, MA_DOB) = @DAY AND DATEPART(MONTH, MA_DOB) = @Month";
        DataSet ds = dt.ExecuteDataSet(str);

I want to compare Day & month with the Date of birth in table.

How can i remove this error.
Posted

1 solution

C#
dt.OpenCon();
string str = "SELECT MA_First_Name,MA_Email_Id FROM Master_Applicant WHERE DATEPART(DAY, MA_DOB) = @DAY AND DATEPART(MONTH, MA_DOB) = @Month";
SqlCommand cmd = new SqlCommand(str);
cmd.Parameters.AddWithValue("@DAY", DateTime.Today.Day);
cmd.Parameters.AddWithValue("@Month", DateTime.Today.Month);
DataSet ds = dt.ExecuteDataSet(cmd);

I have change the sequence of adding parameters and executing sql statement, first create the command with your sql statement and add parameters to it. finally execute the command.
 
Share this answer
 
v2
Comments
Member 11221185 22-Jul-15 6:35am    
thanks for this but previously i did same code but it will shows same error thats the reason change sequence but still showing the same problem
DamithSL 22-Jul-15 6:51am    
what is ExecuteDataSet? are you using library/helper class?
any way you can do the same without parameters for example change the sql as

SELECT MA_First_Name,MA_Email_Id FROM Master_Applicant
WHERE Month(MA_DOB) = Month(CURRENT_TIMESTAMP)
AND Day(MA_DOB) = Day(CURRENT_TIMESTAMP)
Member 11221185 22-Jul-15 7:01am    
Thank u so much. My problem has been solved.

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