pengyouak / DBUtil

.net 下常用的数据库访问工具,支持sqlserver2008、oracle、mysql、postgresql、access、sqlite net framework4.5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DBUtil

.net 下常用的数据库访问工具,支持sqlserver、oracle、mysql、postgresql、sqlite、access 运行平台:net framework4.5

使用说明

  1. 安装依赖:
Install-Package DBUtil -Version 1.0.0
  1. 创建数据库操作对象
DBUtil.IDbAccess iDb = DBUtil.IDBFactory.CreateIDB("Data Source=.;Initial Catalog=JACKOA;User ID=sa;Password=xx;","SQLSERVER");
  1. 查询
String str=iDb.GetFirstColumnString("select Name from SysUser");
DataTable dt = iDb.GetDataTable("select * from test2");
DataSet ds = iDb.GetDataSet("select * from test2;select * from test2;"); 
  1. 分页查询
DBUtil.IDbAccess iDb = DBUtil.IDBFactory.CreateIDB(@"Data Source=localhost;Initial Catalog=imgserver2;User ID=root;Password=123456;", "MYSQL");
string selectSql = "select * from test2";
string orderSql = "order by id desc";
int pageSize = 10;
int pageIndex = 1;
string sqlFinal = iDb.GetSqlForPageSize(selectSql, orderSql, pageSize, pageIndex);
Console.WriteLine(sqlFinal);//select * from test2 order by id desc limit 0,10
  1. 参数化sql
DataTable dt = iDb.GetDataTable(string.Format("select * from test2 where name like {0}", iDb.paraPrefix + "name"), new IDbDataParameter[] {
      iDb.CreatePara("name","%小%")
 });
  1. ID生成
int id = iDb.IDSNOManager.NewID(iDb, "test", "id");

About

.net 下常用的数据库访问工具,支持sqlserver2008、oracle、mysql、postgresql、access、sqlite net framework4.5


Languages

Language:C# 100.0%