今天的日期在Access中 [英] Todays date In Access

查看:88
本文介绍了今天的日期在Access中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何从DOB与今天的日期匹配的访问数据库中获取记录..



谢谢..

Hi,

How to get records from access database where DOB matches with today''s Date..

Thank You..

推荐答案

希望这样做。



string query = 选择id,来自Book的名称MONTH(DOB)=+ DateTime.Now.Month +和Day(DOB)=+ DateTime.Now.Day;
hope this would do.

string query = "select id,name from Book where MONTH(DOB)= "+DateTime.Now.Month +" and Day(DOB)=" +DateTime.Now.Day ;


这个''从Access数据库中选择的一个例子,你已经编辑了查询和你的数据库的路径......好的锁定



This''s an example of selecting from Access database,you have edit the query and the path of your DB... good lock

using System.Data.SqlClient;
using System.Data.OleDb;





OleDbConnection conn = new OleDbConnection();

String connectionString = @Provider = Microsoft.JET.OlEDB.4.0;

+ @Data Source = E:\DB。 mdb;

conn = new OleDbConnection(connectionString);

conn.Open();



string query =select id,book from Book;;



OleDbCommand command = new OleDbCommand(query,conn);

OleDbDataReader reader = command.ExecuteReader();

试试

{

while(reader.Read())

控制台。 WriteLine(String.Format({0} {1},读者[0],读者[1]));



}

终于

{

reader.Close();

conn.Close();

}



OleDbConnection conn = new OleDbConnection();
String connectionString = @"Provider=Microsoft.JET.OlEDB.4.0;"
+ @"Data Source=E:\DB.mdb";
conn = new OleDbConnection(connectionString);
conn.Open();

string query = "select id,name from Book;";

OleDbCommand command = new OleDbCommand(query, conn);
OleDbDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
Console.WriteLine(String.Format("{0} {1}", reader[0], reader[1]));

}
finally
{
reader.Close();
conn.Close();
}


这篇关于今天的日期在Access中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆