发布一个轻量级的SQLSERVER数据处理库 DotNetSQL
DotNetSQL是一个轻量级的数据处理封装,建议用作项目数据持久层, 支持 MSSQL2000/2005, 2008下未测试. 可以满足常规的数据处理需要.适合于基于ASP.NET中小型项目! 能够帮助初学者在一定程度上提高开发效率. DotNetSQL主要分以下模块 DotNetSQL.Proc :执行常
DotNetSQL是一个轻量级的数据处理封装,建议用作项目数据持久层, 支持 MSSQL2000/2005, 2008下未测试. 可以满足常规的数据处理需要.适合于基于ASP.NET中小型项目!
能够帮助初学者在一定程度上提高开发效率.
DotNetSQL主要分以下模块
DotNetSQL.Proc :执行常规的存储过程,包括返回datatable,dataset,sqldatareader,return,output
DotNetSQL.Sql:执行常规的sql语句,提取了sqlhelper的基本操作方法.
DotNetSQL.ORM.Sql : 常规的模型操作,insert,update,delete Model
DotNetSQL.ORM.Proc :基于存储过程的模型操作
DotNetSQL.Config:动态配置 (非web.config),适合于winForm
DotNetSQL.Cache:目前只开放了存储过程参数名称缓存,暂无数据缓存.
简单的列出几个调用例子:
一,普通调用存储过程
CREATE PROCEDURE [dbo].[sp_Test]
@a varchar(20),
@b int,
@c float,
@d text,
@e datetime,
@f int output,
@g varchar(20) output
AS
BEGIN
SET NOCOUNT ON;
--逻辑处理代码
END
这是一个简单的存贮过程,里面关系到了输入参数,输出参数,用DotNetSQL执行代码如下
Code
using DotNetSQL.Proc;
ExecuteProc ep = new ExecuteProc();
Dictionarystring, object> Out;
int f;
string g;
Out=ep.RunProc("sp_Test","LiLei",20,32.3,"这里是长文本",DateTime.Now);
//参数说明
//RunProc(存储过程名称,参数a,参数b,参数c,参数d,参数e) 无需再每个参数都new一次SqlParameter对象
//读取output参数
if(Out.ContainsKey("@f")){
f=(int)Out["@f"];
}
if(Out.ContainsKey("@g")){
g=Out["@g"].ToString();
}
此外 ExecuteProc下还有多个方法,例如无任何返回值,返回DataTable,SqlDataReader,DataSet等等.
另外备注一下使用DotNetSQL执行存储过程与常规ADO.NET操作的性能对比.
以上测试是在我的小本本上测试结果,两者误差基本在2ms内.
二,基于ORM的数据操作
C# Code(Model类)
using System;
using DotNetSQL.ORM; //必需引用该命名空间
[Property("Member")] //设置该model对应的表名
public class Member
{
public Member()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
private int _id;
private string _name;
private bool _sex;
private decimal _money;
private DateTime _addtime;
private string _ext;
[Property(ColumnKeyType.PrimaryKeyAndIdentity)] //表示Id列为该表的主键且自增
public int Id
{
get
{ return _id; }
set
{ _id = value; }
}
public string Name
{
get
{ return _name; }
set
{ _name = value; }
}
public bool Sex
{
get
{ return _sex; }
set
{ _sex = value; }
}
[Property(ColumnKeyType.ReadOnly)] //表示在处理数据时,该列为只读,即不参与修改.
public decimal Money
{
get
{ return _money; }
set
{ _money = value; }
}
public DateTime AddTime
{
get
{ return _addtime; }
set
{ _addtime = value; }
}
[Property(ColumnKeyType.Extend)] //表示该列为扩展列,当数据库表中不存在该字段时,可以标识该属性
public string Ext
{
get
{ return _ext; }
set
{ _ext = value; }
}
}
//ColumnKeyType详细枚举请参考文档
注:Model类中的字段必需于数据库中表的字段名称相同,包括大小写,建议使用代码生成器生成Model!
DotNetSQL的操作代码如下
Code
Member memberModel = new Member();
ORMToSQL ormToSql = new ORMToSQL();
//根据主键(Id)得到实体。
memberModel=ormToSql.GetModelMember>(1); //得到Id=1的数据行(实体)
if(memberModel!=null)
{
Response.Write (memberModel.Name);
}
//插入一个新的实体到数据库中
memberModel.Name="sun.Lei";
memberModel.Sex=false;
memberModel.Money=45.46; //因为在model类中,给该列标识了ReadOnly属性,所以不会插入该列值
memberModel.AddTime = DateTime.Now;
int key=ormToSql.InsertModelMember>(memberModel); //插入数据,并返回该条数据的自增ID
//update,delete都类似,此外以上方法都有相关重载,例如更新指定的列,详情参照文档。
DotNetSQL还集成了基于存储过程的模型操作。
DotNetSQL也集成了sqlhelper中的基本操作方法。
具体请参见文档,点击下载
欢迎大家批评指正,如果你对DotNetSQL感兴趣可以向我索要源码!也希望DotNetSQL能够帮助初学者实现快速开发!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

For objects with the same name that already exist in the SQL Server database, the following steps need to be taken: Confirm the object type (table, view, stored procedure). IF NOT EXISTS can be used to skip creation if the object is empty. If the object has data, use a different name or modify the structure. Use DROP to delete existing objects (use caution, backup recommended). Check for schema changes to make sure there are no references to deleted or renamed objects.

The import steps are as follows: Copy the MDF file to SQL Server's data directory (usually C:\Program Files\Microsoft SQL Server\MSSQL\DATA). In SQL Server Management Studio (SSMS), open the database and select Attach. Click the Add button and select the MDF file. Confirm the database name and click the OK button.

When the SQL Server service fails to start, here are some steps to resolve: Check the error log to determine the root cause. Make sure the service account has permission to start the service. Check whether dependency services are running. Disable antivirus software. Repair SQL Server installation. If the repair does not work, reinstall SQL Server.

To view the SQL Server port number: Open SSMS and connect to the server. Find the server name in Object Explorer, right-click it and select Properties. In the Connection tab, view the TCP Port field.

If you accidentally delete a SQL Server database, you can take the following steps to recover: stop database activity; back up log files; check database logs; recovery options: restore from backup; restore from transaction log; use DBCC CHECKDB; use third-party tools. Please back up your database regularly and enable transaction logging to prevent data loss.

SQL Server database files are usually stored in the following default location: Windows: C:\Program Files\Microsoft SQL Server\MSSQL\DATALinux: /var/opt/mssql/data The database file location can be customized by modifying the database file path setting.

If the SQL Server installation fails, you can clean it up by following these steps: Uninstall SQL Server Delete registry keys Delete files and folders Restart the computer

SQL Server English installation can be changed to Chinese by following the following steps: download the corresponding language pack; stop the SQL Server service; install the language pack; change the instance language; change the user interface language; restart the application.
