一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

用 System.Reflection.Emit 来自动生成调用储存过程的实现

时间:2008-01-12 编辑:简简单单 来源:一聚教程网

/****************************************************************
*
* 用 System.Reflection.Emit 来自动生成调用储存过程的实现!
*
* By http://lostinet.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);

热门栏目