惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - LiShijin.Net

即刻完成你的ASP.NET程序 ASP.NET 2.0,无刷新页面新境界! ASP.NET四种页面导航方式之比较与选择 十天学会ASP.net之第十天 - LiShijin.Net - 博客园 十天学会ASP.net之第九天 - LiShijin.Net - 博客园 十天学会ASP.net之第八天 - LiShijin.Net - 博客园 十天学会ASP.net之第七天 十天学会ASP.net之第六天 用ASP.NET加密Cookie数据 Bill Gates 的大学毕业典礼演讲 asp.net图书请教 .NET程序设计之四书五经 驻留多个 Web 应用程序 确保 ASP.NET 应用程序和 Web Services 的安全 检查表:保护 ASP.NET 的安全 构建安全的 ASP.NET 网页和控件 如何利用窗体身份验证创建 GenericPrincipal 对象 在asp.net中为Web用户控件添加属性和事件 WindowsForm登陆窗体的建立
十天学会ASP.net之第五天 - LiShijin.Net - 博客园
http://blog.csdn.net/byebye8742/ · 2004-08-11 · via 博客园 - LiShijin.Net

 

学习目的:学会连接两种数据库

对于ASP来说,我们常用的数据库无非是ACCESS和SQL SERVER,对于ASP.NET也是,不过ASP.NET对于SQL SERVER有专门的连接组件而不推荐用OLE DB。

首先看一下ACCESS的连接数据库并打开;

string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
strConnection+=Server.MapPath("*.mdb"); //*就是数据库的名字
OleDbConnection objConnection=new OleDbConnection(strConnection);
objConnection.Open();


dim objConnection as OleDbConnection
objConnection=new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("*.mdb"))
objConnection.Open()

下面再看一下SQL SERVER的连接数据库并打开;

string strConnection="server=数据库连接;uid=用户名;pwd=密码;database=数据库名字";
SqlConnediob objConnection=new SqlCOnnection(strConnection);
objConnection.Open();


dim objConnection as SqlConnectiom
objConnection=new SqlConnection("server=数据库连接;uid=用户名;pwd=密码;database=数据库名字")
objConnection.Open()

实际上,在大多数地方SQL SERVER和ACCESS的区别除了连接语句,其他定义语句也就是SQL××和OLEDB××的区别

另外,如果是ACCESS数据库的话在ASPX文件的开头需要包括下列语句:
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
如果是SQL SERVER则需要包括以下语句:
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>

今天就说到这里,明天开始讲数据库的读取。