003. 连接access数据库代码
1. 前端aspx中的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>配置Access数据库连接</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
2. 后台.cs文件中的代码
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.OleDb; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string con_access = ConfigurationManager.AppSettings["accessCon"].ToString();//获取配置文件中的数据库连接字符串
Response.Write("Aceess数据库连接字符串:" + con_access);//输出获取的数据库字符串信息
OleDbConnection oCon = new OleDbConnection(ConfigurationManager.AppSettings["accessCon"]);
try
{
oCon.Open();//打开数据库连接
Response.Write("<script>alert('连接成功')</script>");
oCon.Close();//关闭数据库连接
}
catch (Exception ex)
{
Response.Write("<script>alert(" + ex.ToString() + ")</script>");
}
}
}
3. web.config中的部分代码
</configSections>
<appSettings>
<add key="accessCon" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|db_access.mdb"/>
</appSettings>
<connectionStrings/>
003. 连接access数据库代码的更多相关文章
- PHP连接Access数据库代码
使用php的odbc函数,不创建数据源. $connstr="DRIVER=Microsoft Access Driver (*.mdb);DBQ=".realpath(" ...
- (转)PHP连接数据库之PHP连接MYSQL数据库代码
PHP连接数据库之PHP连接MYSQL数据库代码 < ?php $mysql_server_name='localhost'; //改成自己的mysql数据库服务器 $mysql_usernam ...
- JSP连接access数据库
一个用jsp连接Access数据库的代码. 要正确的使用这段代码,你需要首先在Access数据库里创建一username表,表里面创建两个字符型的字段,字段名分别为:uid,pwd,然后插入几条测试数 ...
- 【.net 深呼吸】连接Access数据库应注意的几点
本地数据库可以有Y种选择,比如Sqlite.SQL Server Express.SQL Local DB.SQL Server CE.Access等,本文老周选用比较著名的Access本地数据库,在 ...
- C#连接Access数据库(详解)
做一个用VS2012的C#连接Access数据库的备忘, SQL数据库固然强大,有大微软的强力技术支持,LINQ的方便操作,但是如果写一个小程序对数据库方面没有什么大的要求的话,将来在数据库方面就可以 ...
- php连接Access数据库错误及解决方法
<?php $connstr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("data.m ...
- php连接Access数据库的三种方法
http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2009/1115/3524.html 虽然不是一个类但先放这儿吧 最近想把一个asp的网站改成 ...
- 具体解释VB中连接access数据库的几种方法
在VB中,连接ACCESS数据库的方法主要有以下三种 使用ADO对象,通过编写代码訪问数据库 Connection 对象 ODBC数据源 使用ADO Data 控件高速创建数据库连接 有三种连接方法 ...
- .NET(C#)连接各类数据库代码-集锦
1.C#连接连接Access 复制代码代码如下: using System.Data; using System.Data.OleDb; .. string strConnection=& ...
随机推荐
- PHP安装编译配置参考
编辑安装php的参考配置: ./configure --prefix=/usr/local/php-5.6.8 --with-config-file-path=/usr/local/php-5.6.8 ...
- What is hmux in resin?
When I start the Resin server it says hmux listening to localhost:6802 What is this hmux? Is this a ...
- Get start with Android development
Firstly we should install the right version of JDK and JRE, there are two version of ADK for differe ...
- 数据结构《9》----Threaded Binary Tree 线索二叉树
对于任意一棵节点数为 n 的二叉树,NULL 指针的数目为 n+1 , 线索树就是利用这些 "浪费" 了的指针的数据结构. Definition: "A binary ...
- 转载 javascript中的正则表达式总结 一
定义正则表达式的方法 定义正则表达式的方法有两种:构造函数定义和正则表达式直接量定义.例如: var reg1 = new RegExp('\d{5, 11}'); // 通过构造函数定义 var r ...
- iPhone各控件的默认高度
1.状态栏 状态栏一般高度为20像素,在打手机或者显示消息时会放大到40像素高,注意,两倍高度的状态栏在好像只能在纵向的模式下使用.如下图 用户可以隐藏状态栏,也可以将状态栏设置为灰色,黑色或者半透明 ...
- C# 控件不刷新问题
/********************************************************************** * C# 控件不刷新问题 * 说明: * 当网络连接出问 ...
- Intellij IDEA 工具快捷键
IntelliJ Idea 常用快捷键列表 Alt+回车 导入包,自动修正Ctrl+N 查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L 格式化代码Ctrl+Alt+O 优化导入的类 ...
- What books does Bjarne Stroustrup suggest to master C++?
QUESTION : What books does Bjarne Stroustrup suggest to master C++? ANSWER: A Tour of C++ is a quick ...
- IE6 IE7下文字显示竖排的解决办法
IE下文字显示竖排的解决办法: white-space:nowrap;