使用C#与MS ACCESS数据库的ASP.NET连接 [英] ASP.NET Connection with MS ACCESS DATABASE USING C#

查看:100
本文介绍了使用C#与MS ACCESS数据库的ASP.NET连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Developers !!!!

我想使用MS ACCESS数据库和C#语言建立一个ASP.NET网站.我进行了很多搜索,但找不到书面答案.
每当我尝试找到连接性解决方案时,我在Google搜索中找到的代码就是Like
< pre>
使用System.Data.Oledb;


__________________________________

Hello Developers!!!!

I want to build a ASP.NET website by using a MS ACCESS database and C# Language.I have searched a lot but i can''t find write answer.
Whenever i try to find connectivity solution, The code that i found on Google search is Like
<pre>
using System.Data.Oledb;


__________________________________

namespace consample
{
pubic class OledbConnection
{
public void Perform()
{
OledbConnection con= new OledbCOnnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb")//Data provider for MS ACCESS
con.Open();
OLEDBCommand cmd=new OLEDBCOmman();
cmd.Connection=con;
cmd.CommandType=CommandType.Text;
cmd.CommandText="Select * from emp";
OledbDataReader dr= new OledbDataReader();
dr=cmd.Executereader();
while (dr.Read()==true)
{
/// Do some coding here
}
}
}
}


__________________________________________


我完全感到困惑,如果我们要在Internet服务器上上传站点,为什么他们只给出本地主机或C:\路径.
请帮我解决这个问题.我将非常感谢您.


__________________________________________


I am totally confused that why they only give local host or C:\ path if we want to upload our site on Internet server.
Please help me out to sort this Problem. I will be very thankful to You.

推荐答案

您可以使用Server.MapPath()在connectionString中定位访问文件,以便在应用程序所在的已部署位置中搜索.这里的主要目的是在运行时应用程序应该能够找到访问数据文件.
代码片段:
You can use Server.MapPath() to locate the access file in connectionString so that it searches in deployed location where application resides. Here main purpose is at runtime application should be able to locate the access data file.
code snnipet:
OledbConnection con= new OledbCOnnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("mydatabase.mdb")+";";



请告诉我们,它对您有什么帮助.



Please let us know whethe it helps you.


这篇关于使用C#与MS ACCESS数据库的ASP.NET连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆