asp.net连接access数据库进行添加更新删除查询操作
连接access数据库代码,写在一个单独的类里
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace AppWebDLL
{
public class ConnApp
{
public OleDbConnection getCon() {
string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+System.Web.HttpContext.Current.Server.MapPath("App_Data\\UserDB.mdb")+";Jet OLEDB:Database Password=admin";
OleDbConnection objConnection = new OleDbConnection(strConnection);
return objConnection;
}
}
}
我这习惯这样写的,在这里System.Web.HttpContext.Current.Server.MapPath是用来取得access的相对路径的,在这个类里想要使用System.Web.HttpContext.Current.Server.MapPath,先要引用system.web这个类。
增删改查代码,以我的类写的,这里要注意一个,如果你的字段和access的关键字一样,那么你就要在你的字段上加 [ ],如password是access的关键字,如果你的字段有这个,你在做操作的时候就要这样写[password]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AppWebDLL;
using System.Data;
using System.Data.OleDb;
using System.Collections;
namespace AppBLL
{
public class Land
{
ConnApp capp = new ConnApp();
OleDbConnection db;
OleDbCommand olecom = null;
//查询所有用户
public ArrayList GetAllUser() {
ArrayList alluserlist = new ArrayList();
db = capp.getCon();
try
{
string sql = "select USERNAME from userinfo";
olecom = new OleDbComman
相关文档:
ASP.NET页面间的传值的几种方法(转载)
ASP.NET WEB FORMS 给开发者提供了极好的事件驱动开发模式。然而这种简单的应用程序开发模式却给我们带来了一些小问题,举个例子,在传统的ASP应用程序中,你能够通过POST方法很容易的把一个值或多个值从一个页面传送到另一个页面,用同样的方法在ASP.NET中实现有点麻烦 ......
此处提供的代码用来实现当asp.net页面中的某个Button被点击后disable掉该页面中所有的Button,从而防止提交延时导致的多次提交。基于之前的onceclickbutton脚本.
//ASP.NET中防止页面多次提交的代码:javascript< script language=”javascript”> < !– function disableOtherSubmit() {
var obj ......
引用命名空间
using System.Diagnostics;
string sPath = "d:\\test\\test.bat";
string sDict = "d:\\test\\";
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe ......
Cookie 提供了一种在 Web 应用程序中存储用户特定信息的方法。例如,当用户访问您的站点时,您可以使用 Cookie 存储用户首选项或其他信息。当该用户再次访问您的网站时,应用程序便可以检索以前存储的信息。
什么是 Cookie?
Cookie 是一小段文本信息,伴随着用户请求和页面在 Web 服务器和浏览器之间传递。Cookie 包含每 ......