Click here to Skip to main content
15,891,743 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
hi..

can any body help me with the code....

C#
public void alreadyExists()    // function to check the existing records
    {
        DateTime tdy = DateTime.Now;
        DateTime aft2dy = DateTime.Now.AddDays(2);

        string str="select due_date from mConfirm where due_date BETWEEN '"+tdy+"' AND '"+aft2dy+"'";

        sda = new SqlDataAdapter(str, cn);
        ds1 = new DataSet();
        sda.Fill(ds1);    // HERE I M GETTING THE EXCEPTION.... AS
                           //"public void alreadyExists()    // function to check the existing records"

        string d = ds1.Tables[0].Rows[0].ItemArray[0].ToString();
        if ((Convert.ToDateTime(d) - DateTime.Today).TotalDays <= 2)    // HERE WHAT SHOULD I DO
        {
            LblAlreadyExists.Text = "Already Under Process";
        }



    }
Posted
Updated 23-Feb-12 16:30pm
Comments
Sergey Alexandrovich Kryukov 23-Feb-12 22:46pm    
Not a question. Help with what?
--SA
Sergey Alexandrovich Kryukov 23-Feb-12 22:50pm    
Very bad code. Mixed data layer calculation with UI, hard-coded string and UI action. Ever head of functions? predicates? DataReader? Why filling whole data set if you are using only one record? Why, by the way?
--SA
Ganesan Senthilvel 23-Feb-12 22:52pm    
Not sure why the exception comes from the comment line. Could you share the complete source code?
Varun Sareen 23-Feb-12 22:59pm    
what you are doing in code? Its very confusing :(
Tejas Vaishnav 23-Feb-12 23:01pm    
what was the error message..

1 solution

Looks like the problem is your SQL
C#
string str="select due_date from mConfirm where due_date BETWEEN '"+tdy.ToShortDateString()+"' AND '"+aft2dy.ToShortDateString()+"'";
 
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