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:
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);

What I have tried:

C#
double Month = Convert.ToDouble(DropDownList1.SelectedItem.Value);
     double Year = Convert.ToDouble(DropDownList2.SelectedItem.Value);
     string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
     using (SqlConnection con = new SqlConnection(constr))
     {
         using (SqlCommand cmd = new SqlCommand("SELECT a.FirstName +' '+ a.MiddleName +' '+a.LastName as ApplicantName,a.ApplicationNo,b.[ApplicationDate] FROM [Applicant]as a,Application as b where a.ApplicationNo= b.ApplicationNo and MONTH(b.ApplicationDate) = @Month and YEAR(b.ApplicationDate) = @Year "))
         //using (SqlCommand cmd = new SqlCommand("SELECT a.FirstName +' '+ a.MiddleName +' '+a.LastName as ApplicantName,a.ApplicationNo,b.[ApplicationDate] FROM [Applicant]as a,Application as b where a.ApplicationNo= b.ApplicationNo and YEAR(b.ApplicationDate) = @Year "))
         {
             SqlParameter param = new SqlParameter();
             param.ParameterName = "@Month";
             param.Value = Month;

             cmd.Parameters.Add(param);
             //SqlParameter param = new SqlParameter();
              param.ParameterName = "@Year";
              param.Value = Year;
             cmd.Parameters.Add(param);
Posted
Updated 29-Sep-16 4:44am
Comments
Suvendu Shekhar Giri 29-Sep-16 5:17am    
You want to filter by Month and Year right?
Karthik_Mahalingam 29-Sep-16 6:16am    
what is the issue?
phil.o 29-Sep-16 6:28am    
Please use the green "Improve question" button and show us the rest of the code, where you execute the command and get the results.
[no name] 29-Sep-16 8:19am    
Please use the green "Improve question" button and ask a question or describe a problem. Just dumping your code into a posting is not asking a question.

1 solution

Well, right off the bat, you need to create separate SqlParameter objects for each parameter. Otherwise, you're passing the same value for the month and year. You probably won't be able to get the data you're interested in until you fix that (the @Month parameter will be the same as the @Year parameter).
 
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