迷失网络

如果你误读成“迷失公园”或“迷失侏罗纪”,那你可能真的迷失网络了。
随笔 - 88, 评论 - 1932, 引用 - 106

导航

关于

lostinet@lostinet.com这个油箱不能用了。因为空间没了,lostinet.com指向为127.0.0.1 。。。

标签

每月存档

最新留言

广告

 

最近有病呆在家里,不是次就是睡,不只日夜颠倒了,还胖了不少。
不过空余的时间总不能浪费掉,所以开始了一个新的跨数据库访问组件。
不过那个组件要写比较长时间了,所以一时不会做得完。

不过今天用其中的技术做了个有用的例子,发到这里给大家参考一下。

这个例子的大概意思是,程序员参考存储的定义,写出一个接口出来,并且不需要写具体的实现代码,就能调用该接口了!
也就是说,程序员不需要写以下类似的代码了:

SqlCommand cmd=new SqlCommand("UpdateTopic",conn);
cmd.CommandType
=CommandType.StoredProcedure;

SqlParameter pTitle
=new SqlParameter("@title",SqlDbType.NVarChar,80);
pTitle.Value
=title;
cmd.Parameters.Add(pTitle);

//.


程序的例子如下

/****************************************************************\
 * 
 * 用 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);

                
//调用储存过程并且显示

                ShowData(
"CustOrderHist ALFKI",nsp.CustOrderHist("ALFKI"));

                ShowData(
"Employee Sales By Country",nsp.EmployeeSalesByCountry(new DateTime(1998,1,1),new DateTime(1999,1,1)));

            }

        }


        
static void ShowData(string title,object data)
        
{
            Form f
=new Form();
            f.Width
=600;
            f.Height
=480;
            f.Text
=title;

            DataGrid grid
=new DataGrid();            
            grid.Dock
=DockStyle.Fill;
            grid.DataSource
=data;

            f.Controls.Add(grid);
            f.ShowDialog();
        }


    }

}


//实现方法(不完整)


从这里复制代码:

打印 | 张贴于 2004-11-19 04:16:00 | Tag:DotNet

留言反馈

#回复: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
好,很好 ,继续努力
2007-05-15 14:29:00 | [匿名:江山]
#回复: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
好,很好
2007-05-15 14:27:00 | [匿名:江山]
#回复: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
自动实现调用存储过程的接口怎么用????
2007-01-17 09:32:00 | [匿名:cet]
#re:用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
用 System.Reflection.Emit 自动实现调用存储过程的接口ooeess
2005-06-08 16:33:00 | [匿名:差压变送器]
#re:用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
^_~,pretty good!csharpsseeoo
2005-05-13 16:24:00 | [匿名:水分测定仪]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
<zhichi>
2005-05-08 04:41:00 | [匿名:fooo]
#re:用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
^_~,pretty good!18showsseeoo
2005-04-26 12:49:00 | [匿名:接触角测量仪]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
你的lostinet.com上面的文件下载好象都失效了。
论坛也上不去:)

没有空间吗?
2005-04-23 23:36:00 | [匿名:小牛]
#re:用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
^_^,Pretty Good!
2005-04-15 19:26:00 | [匿名:测振仪]
#re:用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
^_^,Pretty Good!
2005-04-10 19:44:00 | [匿名:试验机万能试验机]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
Lostinet,真棒
2004-12-09 16:54:00 | [匿名:tim]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
有病也能出精品,支持!
2004-11-23 13:14:00 | [匿名:srz]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
支持并学习ing~
注意身体啊 :)
2004-11-20 14:41:00 | [匿名:木野狐]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
:)

修正一下:

//this.ExecuteXXX(this._cmd_MethodName)
if(!nores)
{
ilg.Emit(OpCodes.Ldarg_0);
}

ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Ldfld,field_cmd);
ilg.Emit(OpCodes.Callvirt,method_Execute);
2004-11-19 20:17:00 | [匿名:Lostinet]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
老大,不会吧 !你巴巴地就贴了个这样的上来,强烈要求删除。
2004-11-19 17:27:00 | [匿名:javafaq2004]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
对存储过程不感冒。因为要考虑支持多数据库,不能写什么存储过程(不利于移植)。以前使用op的时候用存储过程比较多。
2004-11-19 08:33:00 | [匿名:jiezhi]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
对存储过程不感冒。因为要考虑支持多数据库,不能写什么存储过程(不利于移植)。以前使用op的时候用存储过程比较多。
2004-11-19 08:33:00 | [匿名:jiezhi]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
那个加减号好,有创意。
2004-11-19 05:17:00 | [匿名:javafaq2004]
#re: 用 System.Reflection.Emit 自动实现调用存储过程的接口 编辑
看也不看就支持
2004-11-19 05:16:00 | [匿名:javafaq2004]
对不起,目前本随笔不允许发表新评论.

Powered by: Joycode.MVC引擎 0.5.2.0