2010-07-18 64 views
0

我需要运行我在Access中创建一个表的查询,名为“MyQuery”。如何运行通过C#在Access中创建表的查询?

如何在C#代码中运行此查询?

+0

什么是“扔”在问题的标题是什么意思? – stakx 2010-07-18 11:26:54

+0

我猜这意味着'通过' – 2010-07-20 20:34:14

+0

那么为什么没有人只是编辑标题,然后呢? – 2010-07-21 18:56:46

回答

3

看看this thread on vbCity,这似乎与你的问题完全相同。

您的代码可能再看看与此类似:

using System.Data; 
using System.Data. 

using (IDbConnection conn = new OleDbConnection(...)) // <- add connection string 
{ 
    conn.Open(); 
    try 
    { 
     IDbCommand command = conn.CreateCommand(); 

     // option 1: 
     command.CommandText = "SELECT ... FROM MyQuery"; 

     // option 2: 
     command.CommandType = CommandType.TableDirect; 
     command.CommandText = "MyQuery"; 

     // option 3: 
     command.CommandType = CommandType.StoredProcedure; 
     command.CommandText = "MyQuery"; 

     using (IDataReader reader = command.ExecuteReader()) 
     { 
      // do something with the result set returned by reader... 
     } 
    } 
    finally 
    { 
     conn.Close(); 
    } 
} 
相关问题