Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在c中基于日期查询datetime#_C#_Ms Access_Jet_Dd - Fatal编程技术网

C# 如何在c中基于日期查询datetime#

C# 如何在c中基于日期查询datetime#,c#,ms-access,jet,dd,C#,Ms Access,Jet,Dd,我有一个带有日期时间列的MS Access数据库。 例如:03/08/2009 12:00:00 AM 我需要基于日期的查询,如: select * from tablename where date='03/08/2009' 我希望将数据显示为03/08/2009 12:00:00 AM 我将如何用C#编写此查询? 请帮帮我。以下是一些示例代码,在控制台应用程序中使用C#访问access DB。如果需要,可以将此代码改编为windows或ASP.NET /* Replace with the

我有一个带有日期时间列的MS Access数据库。
例如:
03/08/2009 12:00:00 AM

我需要基于日期的查询,如:

select * from tablename where date='03/08/2009'
我希望将数据显示为
03/08/2009 12:00:00 AM

我将如何用C#编写此查询?
请帮帮我。

以下是一些示例代码,在控制台应用程序中使用C#访问access DB。如果需要,可以将此代码改编为windows或ASP.NET

/* Replace with the path to your Access database */
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;";

try
{
using(OleDbConnection conn = new OleDbConnection(connectionString)
{
   conn.Open();       
   string myQuery = "Select * FROM tableName WHERE date='03/02/2009'";       
   OleDbCommand cmd = new OleDbCommand(myQuery, conn);
   using(OleDbDataReader reader = cmd.ExecuteReader())
   {
      //iterate through the reader here
      while(reader.Read())
      {
         //or reader[columnName] for each column name
         Console.WriteLine("Fied1 =" + reader[0]); 
      }
   }
}

}
catch (Exception e)
{
   Console.WriteLine(e.Message);
}

下面是一些在控制台应用程序中使用C#访问access DB的示例代码。如果需要,可以将此代码改编为windows或ASP.NET

/* Replace with the path to your Access database */
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;";

try
{
using(OleDbConnection conn = new OleDbConnection(connectionString)
{
   conn.Open();       
   string myQuery = "Select * FROM tableName WHERE date='03/02/2009'";       
   OleDbCommand cmd = new OleDbCommand(myQuery, conn);
   using(OleDbDataReader reader = cmd.ExecuteReader())
   {
      //iterate through the reader here
      while(reader.Read())
      {
         //or reader[columnName] for each column name
         Console.WriteLine("Fied1 =" + reader[0]); 
      }
   }
}

}
catch (Exception e)
{
   Console.WriteLine(e.Message);
}

问题不是编程语言,而是对mdb访问的查询。Access要求在输入日期之前输入单词
DateValue

string myQuery = "Select * FROM tableName WHERE date= DateValue ('03/02/2009')"; 

问题不是编程语言,而是对mdb访问的查询。Access要求在输入日期之前输入单词
DateValue

string myQuery = "Select * FROM tableName WHERE date= DateValue ('03/02/2009')";