Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends,

here i did in my project "REMAINDER" event, so if the remainder date is today means it should display in a label which i wrote in below code.

please help me out how to retrive and match the todays date with remainders date on a particular username.



C#
public void rdisplay()
            {
               
                cmdd = new OleDbCommand("select * from Remainder where [rusername]='" + loginusername + "'", conn);
                conn.Open();
                cmdd.ExecuteNonQuery();
                OleDbDataAdapter da = new OleDbDataAdapter(cmdd);

                da.Fill(ds); 
                

                conn.Close();


   [here its getting error in below var rrow and string remdate  please help me !]
   
             var rrow = ds.Tables[0].Select("[date]");
                string remdate = dt.Rows[0]["date"].ToString();


                DateTime now = DateTime.Now;
                string rnow = "dd/MM/yyyy";
                var rvar = (now.ToString(rnow));

                string rnow2 = "MM/dd/yyyy";
                var rvar2 = (now.ToString(rnow2));
                if (remdate == rvar)
                {
                    lblremdisplay.Content = "Remainder :-" + dt.Rows[0]["your remainder"].ToString() + "";
                }
                else if (remdate == rvar2)
                {
                    lblremdisplay.Content = "Remainder :-" + dt.Rows[0]["your remainder"].ToString() + "";
                }
                else
                {
                    lblremdisplay.Content = "";
                }


thank u .
Posted
Updated 1-Apr-14 2:52am
v2

1 solution

If you would like to fetch values from database for any particular day, your OleDbCommand should looks like:
C#
cmdd = new OleDbCommand("select * from Remainder where [remainderdate]=#" + @yourdate + "#", conn);

Where @yourdate is today in iso format: MM/dd/yyyy

For today, use:
SQL
select *
from Remainder
where [remainderdate]=#Date()#


Date() function[^]

For set of dates:
SQL
select *
from Remainder
where [remainderdate] BETWEEN #03/01/2014# AND #04/01/2014#


BETWEEN ... AND ...[^]
 
Share this answer
 
Comments
Mr.VJ 2-Apr-14 1:59am    
thank u for reply Maciej Los

i did like this

cmdd = new OleDbCommand("select [date]='"+present date+"' from Remainder where [rusername]='" + loginusername + "' ", conn);
conn.Open();
cmdd.ExecuteNonQuery();
OleDbDataAdapter da = new OleDbDataAdapter(cmdd);

//da .Fill(ds);
da.Fill(dt);

conn.Close();


string remdate = dt.Rows[0]["date"].ToString();//but here getting error like date column does belongs to table.
Maciej Los 2-Apr-14 2:05am    
Replace:
dt.Rows[0]["date"].ToString();
with:
dt.Rows[0].ToString();
Maciej Los 2-Apr-14 2:08am    
BTW: Access has got a list of reserved words. One of them is Date. Please see: http://support.microsoft.com/kb/286335/en

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