最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
用 System.Reflection.Emit 来自动生成调用储存过程的实现
时间:2022-06-30 11:26:06 编辑:袖梨 来源:一聚教程网
/****************************************************************
*
* 用 System.Reflection.Emit 来自动生成调用储存过程的实现!
*
* By http://*lo*stinet*.com
*
* Copyrights : Not-Reversed
*
****************************************************************/
//使用的例子
namespace Lostinet.Sample
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
//定义一个接口,用于定义存储过程
interface INorthwindStoredProcedures
{
//定义存储过程对应的方法
DataSet CustOrderHist(string CustomerID);
//如果储存过程名字和方法名字不同,应该用SqlAccessAttribute来进行说明
[SqlAccess("Employee Sales By Country")]
DataTable EmployeeSalesByCountry(DateTime Beginning_Date,DateTime Ending_Date);
//...more...
//MORE Ideas..
//直接执行SQL语句?
//[SqlAccess(SqlAccessType.SqlQuery,"SELECT * FROM Employees WHERE EmployeeID=@EmpId")]
//DataTable SelectEmployee(int EmpId);
}
class ConsoleApplication
{
[STAThread]
static void Main(string[] args)
{
using(SqlConnection conn=new SqlConnection("server=(local);trusted_connection=true;database=northwind"))
{
//一句话就把实现创建了!
//需要传如 SqlConnection 和 SqlTransaction
//SqlTransaction可以为null
//这个好就好在,只要能得到SqlConnection/SqlTransaction就能用这个方法了,所以兼容 Lostinet.Data.SqlScope
INorthwindStoredProcedures nsp=(INorthwindStoredProcedures)
StoredProcedure.CreateStoredProcedureInterface(typeof(INorthwindStoredProcedures),conn,null);
*
* 用 System.Reflection.Emit 来自动生成调用储存过程的实现!
*
* By http://*lo*stinet*.com
*
* Copyrights : Not-Reversed
*
****************************************************************/
//使用的例子
namespace Lostinet.Sample
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
//定义一个接口,用于定义存储过程
interface INorthwindStoredProcedures
{
//定义存储过程对应的方法
DataSet CustOrderHist(string CustomerID);
//如果储存过程名字和方法名字不同,应该用SqlAccessAttribute来进行说明
[SqlAccess("Employee Sales By Country")]
DataTable EmployeeSalesByCountry(DateTime Beginning_Date,DateTime Ending_Date);
//...more...
//MORE Ideas..
//直接执行SQL语句?
//[SqlAccess(SqlAccessType.SqlQuery,"SELECT * FROM Employees WHERE EmployeeID=@EmpId")]
//DataTable SelectEmployee(int EmpId);
}
class ConsoleApplication
{
[STAThread]
static void Main(string[] args)
{
using(SqlConnection conn=new SqlConnection("server=(local);trusted_connection=true;database=northwind"))
{
//一句话就把实现创建了!
//需要传如 SqlConnection 和 SqlTransaction
//SqlTransaction可以为null
//这个好就好在,只要能得到SqlConnection/SqlTransaction就能用这个方法了,所以兼容 Lostinet.Data.SqlScope
INorthwindStoredProcedures nsp=(INorthwindStoredProcedures)
StoredProcedure.CreateStoredProcedureInterface(typeof(INorthwindStoredProcedures),conn,null);
相关文章
- boss智能门锁如何设置密码 04-29
- 王者荣耀世界橘右京厉害吗 04-29
- 《青云劫攻略天赋技能,成就无敌仙侠》(解锁潜能,掌握绝学,成就仙侠传奇) 04-29
- 桃源深处有人家藏经室悟证一至七日通关答案 04-29
- 怎么击败《Saros》中的“破碎崛起”先知 Boss 04-29
- 宫小攻略技能推荐2023(玩转宫小,轻松游戏攻略指南) 04-29