2010-07-18 68 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(); 
    } 
} 
相關問題