在asp.net中创建并连接到访问数据库 [英] create and connect to a access database in asp.net
本文介绍了在asp.net中创建并连接到访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个访问数据库并将asp.net项目连接到该数据库,该怎么做呢?
Hi,
I want to create a access database and connect my asp.net project to that how can I do this?
推荐答案
检查以下链接.
用于创建Access数据库:
http://office.microsoft.com/en-us/access-help/create-an-access-database-HP005187442.aspx [ http://office.microsoft.com/en-us/access-help/create-an-access-database-HP005187442.aspx [ http://www.aspfree.com /c/a/Microsoft-Access/使用ASPNET/连接到Microsoft-Access-database-/ [ http://www.beansoftware.com/ASP.NET-Tutorials/Connecting- Access-SQL-Server.aspx [ ^ ]
Check the following links.
For creating Access database:
http://office.microsoft.com/en-us/access-help/create-an-access-database-HP005187442.aspx[^]
http://office.microsoft.com/en-us/access-help/create-an-access-database-HP005187442.aspx[^]
For connecting to Access to asp.net:
http://www.aspfree.com/c/a/Microsoft-Access/Connecting-to-a-Microsoft-Access-database-with-ASPNET/[^]
http://www.beansoftware.com/ASP.NET-Tutorials/Connecting-Access-SQL-Server.aspx[^]
Access 2007的连接字符串 [^ ]
这是连接字符串.请检查此字符串.
谢谢.
Connection strings for Access 2007[^]
here is the connection string.. check this one.
thanks..
下面的代码将在您的web.config中
The code below will be in your web.config
<connectionStrings>
<add name="ConnectionStringName" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|DatabaseName.mdb;Persist Security Info=True" providerName="System.Data.OleDb"/>
</connectionStrings>
现在下面是在页面后面的类或代码中使用ConnectionString名称的方式
Now below this is how you will use your ConnectionString name in your class or code behind a page
//Method for A Database Connection
public string dbConnection()
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
try
{
// set up and open connection
dbConn = new OleDbConnection(connString);
dbConn.Open();
}
catch (OleDbException exp)
{
MessageBox.Show(exp.Message);
}
return connString;
}
也许您将需要以下名称空间
maybe u will need the following namespace
using System.Configuration;
希望对您有帮助...
Hope it helps...
这篇关于在asp.net中创建并连接到访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文