8
Answers

GetDate

Marvin kakuru

Marvin kakuru

12y
4.2k
1

Hi vulpes,

Thanks a lot I was able to get my program to select date values from access, it worked like light. I have another challenge, I was using some code you had prescribed and worked perfectly when I was using mysql database, however with access it is giving me some trouble.

The code is supposed to select data in my access database where the date of entry and today's date are different by 90 days, below is the code I was using with mysql, but I have edited it to match the OleDb

{

OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\katoto\Documents\Visual Studio 2010\Projects\Genesis Philcollins\data\thyfarm.accdb;Jet OLEDB:Database Password=Kyozi");

            string sql = ("select motherUIC,mother,UIC,Nam,animalsex,TagNo,Status,Owner,Day,Dat,wkno,mont,yr,presence from Herdregistar where DATEDIFF(day, [date], GetDate()) >= 90 AND status like '" + "Incalf" + "'");

            //string sql = ("select motherUIC,mother,UIC,Name,animalsex,TagNo,Status,Owner,Day,Date,wkno,month,year,presence from Herdregistar where DATEDIFF(day, Convert(varchar(10), GetDate(),103), Convert(varchar(10), [date],103)) >= 90");

           

 

 

            DataSet ds;

           

            OleDbCommand cmd = new OleDbCommand();

            OleDbDataAdapter da = new OleDbDataAdapter();

            //SqlDataReader dr = new SqlDataReader();

 

            cmd = new OleDbCommand(sql, cn);

            da = new OleDbDataAdapter(cmd);

            //dr = new SqlDataReader(da);

            // cb = new SqlCommandBuilder(da);

 

 

            ds = new DataSet();

 

           da.Fill(ds, "select motherUIC,mother,UIC,Nam,animalsex,TagNo,Status,Owner,Day,Dat,wkno,mont,yr,presence");

            da.Fill(ds);

            dataGridView1.DataSource = ds.Tables[0];

 

           

 

}

 

When I run the above code I get an error "Undefined function 'GetDate' in expression."

Thanks again,

Best Regards.


Answers (8)