.NET 数据库
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Db
{
/// <summary>
/// Base 的摘要说明。
/// </summary>
public class Base
{
public Base()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
protected static SqlConnection conn =new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
protected static SqlCommand cmd = new SqlCommand(strSp,conn);
protected static SqlDataAdapter da = new SqlDataAdapter();
protected static DataSet ds = new DataSet();
protected static DataView dv = new DataView();
protected static SqlDataReader dr;
protected static SqlParameter[] prams;
protected static string strSp;
protected static SqlDataReader drSelectAll(string strSp)
{
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}//返回一个SqlDataReader
protected static DataSet dsSelectAll(string strSp)
{
da.SelectCommand = new SqlCommand(strSp,conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.Fill(ds);
conn.Open();
try
{
da.SelectCommand.ExecuteNonQuery();
return ds;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Dispose();
conn.Close();
}
}//返回一个SqlDataSet
protected static DataView dvSelectAll(string strSp)
{
cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = new SqlCommand(strSp,conn);
da.Fill(ds);
conn.Open();
try
{
da.SelectCommand.ExecuteNonQuery();
dv = ds.Tables[0].DefaultView;
return dv;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Dispose();
conn.Close();
}
}//返回一个DataView
protected static string strCmd(string strSp,SqlParameter[] prams,SqlDataReader dr)
{
CreateCmd(strSp,prams,dr);
conn.Open();
try
{
cmd.ExecuteNonQuery();
return "1";
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Dispose();
conn.Close();
}
}//返回一个数据库操作
protected static SqlCommand CreateCmd(string strSp, SqlParameter[] prams,SqlDataReader dr)
{
cmd.CommandType = CommandType.StoredProcedure;
if (prams != null)
{
foreach (SqlParameter parameter in prams)
cmd.Parameters.Add(parameter);
}
cmd.Parameters.Add(
new SqlParameter("ReturnValue", SqlDbType.Int, 4,
ParameterDirection.ReturnValue, false, 0, 0,
string.Empty, DataRowVersion.Default, null));
return cmd;
}//返回带参数的命令
protected static bool ExecuteSQLs()
{
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
try
{
int i = (int)cmd.ExecuteScalar();
if(i>0)
{
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Dispose();
conn.Close();
}
}//返回第一行的数据操作
}
}
本篇文章来自<A href='http://w
基于.NET的可重用数据访... 19页 免费 ASPNET封装的数据库访问... 2页 1...用AO.E利DN T的强 大数 据访 问功 能,计 了抽 象 设 的数据访问基类。...
第10 章 ASP.NET 和 ADO.NET 数据库开发技术本章主要介绍 ASP.NET 和 ADO...构架的基类 针对 OLEDB 数据源所设计的数据存取类 针对 Microsoft SQL Server ...
第二章ASPNET 数据库应用程序开发_理学_高等教育_教育专区。ASP.NET 数据库...? 在派生类中访问基类成员。 (3) 多态性 多态性是指不同对象收到相同消息时...
框架提供统一的数据访问技术,与 以前的数据访问技术相比,ADO.NET主要增加了对XML...将其编译到一个动态生成的 .NET Framework 类,该类是从 HttpApplication 基类...
第九章 ASP NET和ADO NET数据库开发技术_计算机...改进而来,它提供平台互用和可收 缩的数据访问功能...提供ADO.NET构架的基类 针对OLEDB数据源所设计的数据...
2013-7-8 ASP.NET概述 数据库访问技术ADO.NET 数据库的连接 显示数据库中的...时候自动编译源代 码,编译后生成了一个基类,以后每次的访问都是直接调用该基类...
在 ADO.NET 之前,程序员在 ASP(Active Server Pages)或 Visual Basic 中使用...ADO.NET 包含 7 个重要的基类,其中 4 个是数据访问类:● DbConnection; ● ...
VB.Net等多种语言,提高了程序的通用性; 提供了丰富的基类函数库,提高了程序...着重讨论了用ASP.NET技术和 ORACLE开发网上选课系统时的数据库访问技术.经过测试...
ASPNET课后习题答案_计算机软件及应用_IT/计算机_专业资料。ASP.NET 网页是...只前进的访问 SqlCommand 类的 CommandText 属性用于获取或设置要对数据源执行的 ...
热门文档