2012-05-01 49 views
1

正确的做法是,我必须在MVC3中开发一个新的应用程序,但不幸的是它必须与经典的asp网站稍微集成。这不会永远保留,因为旧网站会在某个时候获得更新,但尚未完成。但同时,新的MVC3应用程序需要对旧数据库的一点访问权限,这是旧的MS Access .mdb,而新的应用程序将使用SQL Server 2008.将一个MS Access(.mdb)数据库连接到一个MVC3 Web应用程序

我会大大感谢它,如果有人可以给我一些如何连接到访问数据库的例子,以及如何执行SQL查询(我很好写的SQL,只是不知道如何从我的mvc3应用程序执行数据库)。

在此先感谢

编辑:我没有得到与旧网站太多的经验,但它似乎使用JET适配器是否有帮助! ;-)

+0

我觉得你的痛苦!访问。啊!查看connectionstrings.com,并在那里有一个连接字符串用于连接访问数据库。这很简单..但是,一旦超过5个人同时开始点击它,它会变得很慢 –

+0

对于实际访问数据库,可以使用Microsoft数据访问应用程序块 –

回答

1
string connectionString = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;Jet OLEDB:Database Password=MyDbPassword; 
public void InsertRow(string connectionString, string insertSQL) 
{ 
    using (OleDbConnection connection = new OleDbConnection(connectionString)) 
    { 
     // The insertSQL string contains a SQL statement that 
     // inserts a new row in the source table. 
     OleDbCommand command = new OleDbCommand(insertSQL); 

     // Set the Connection to the new OleDbConnection. 
     command.Connection = connection; 

     // Open the connection and execute the insert command. 
     try 
     { 
      connection.Open(); 
      command.ExecuteNonQuery(); 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine(ex.Message); 
     } 
     // The connection is automatically closed when the 
     // code exits the using block. 
    } 
} 
2

您的问题需要回答过于粗放详细
给予我给你的东西,一流的检查表来研究

现在不要忘记关闭连接,并使用参数化查询

相关问题