用ASP.NET/C#连接Access和SQLServer数据库

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

首先看一个例子代码片断:
程序代码:

--------------------------------------------------------------------------------
usingSystem.Data;
usingSystem.Data.OleDb;

stringstrConnection="Provider=Microsoft.Jet.OleDb.4.0;";
strConnection+=@"DataSource=C:/BegASPNET/Northwind.mdb";

OleDbConnectionobjConnection=newOleDbConnection(strConnection);
......

objConnection.Open();
objConnection.Close();

ps:
 1."+="后面的"@"符号是防止将后面字符串中的"/"解析为转义字符.
 2.如果要连接数据库文件和当前文件在同一个目录下,还可以使用如下的方法连接:
strConnection+="DataSource=";
strConnection+=MapPath("Northwind.mdb");
这样就可以省得你写一大堆东西了!
 3.要注意连接字符串中的参数之间要用分号来分隔.

例子代码片断:
程序代码:

--------------------------------------------------------------------------------
usingSystem.Data;
usingSystem.Data.SqlClient;

stringstrConnection="userid=sa;password=;";
strConnection+="initialcatalog=Northwind;Server=YourSQLServer;";
strConnection+="ConnectTimeout=30";

SqlConnectionobjConnection=newSqlConnection(strConnection);
...

objConnection.Open();
objConnection.Close();

共2页:上一页1 <script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
个人分类: .net
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭