Terry's blog

Focus on bigdata and cloud.

博客园 首页 新随笔 联系 订阅 管理


  一、导入数据库连接操作(说明:我的数据服务器地址为本地,数据库为sqlserver)
   1 点击 开始->所有程序->Microsoft ®  Business Data Catalog Definition Editor
   2 单击 AddLobSystem->Connect to Database
   3 在Connect Type中选择SqlServer
   4 在Connect String 中输入如下字符串连接
       Data Source=.;Initial Catalog=BOCO;Integrated Security=True,如下图。   

    5 点击 Connect按钮后,即完成了数据库的连接操作。
   我的数据库表结构如下:
    
  二、 把表格添加到Lob System中。
  点击Lob System最右上方的Add Table,把Employee拖到左侧的Design Surface,然后点击 OK,之后在Lob System Name中输入BDCEmployee这后,点击OK.
   


   
现在看一下连接好的BDCEmployee.可见工具给我自动生成了两个方法,Find_Employee通过表格中关键字id查询数据。另一个方法FindAll_Employee是查询表格所有数据。

 三、添加新方法.
      右击 Method->单击Add Method后生成一个名称为Method1的方法。现在的名称不太好,我们改成FindDataByName.方法是:单击Method1,在右侧把Name的值改为FindDataByName,然后单击DefaultDisplayName的值,此时其值也变为FindDataByName.
 右击 FindDataByName下的Filters,单击 Add Filter
   

单击FilterDescriptor1,在其右侧的Name改为name,然后在DefaultDisplayName单击,自动显示为name.
现在我们添加两个参数,一个为输入参数,一个为返回的参数。
1 添加输入参数
右击Parameters,单击Add Parameter,在Choose Parameter Type选择 In
   
单击OK.
更改Parameter0为@Name。
  单击Parameter0,把右侧的Name值改为@Name之后,单击DefaultDisplayName的值其变为@Name。
  右击@Name单击Create Root TypeDescriptor,在FilterDescriptor属性值中单击下拉菜单,选择我们前面的Filter的值:name.把Name属性的值更改为name,单击DefaultDisplayName使其值变为name,此时单击name查看右侧TypeName的值类型为System.String,到此输入参数添加完毕。

2 添加返回参数
  右击Parameters,单击Add Parameter,在Choose Parameter Type选择 Return之后,单击OK。
  更改Parameter1为Result
  单击Parameter1,把右侧的Name值改为Result之后,单击DefaultDisplayName的值使其变为Result。 
3 右击Result 单击Create Root TypeDescriptor
 
   把Result_RootTypeDescriptor更改为DataReader.
   右击DataReader后单击Add TypeDescriptor

 
 如上面方法把TypeDescriptor0改为DataRecord
  添加表格两例数据的输入参数id及name.
 右击DataRecord后单击Add TypeDescriptor,把TypeDescriptor0改为id。
 右击DataRecord后单击Add TypeDescriptor,把TypeDescriptor1改为name.
 到此为至,参数已经添加完成。也许你要问输出参数为什么要添加到如此的深度,那我的理解是只到能数的TypeName的值才为System.String,也即能让其在方法执行时,显示出结果来。如下两个图中的TypeName.
 
  

四、为方法的执行添加一个实例
   方法:右击Instances选择Add Method Instance


在下面的Method Instance Type中选择Finder

点击 OK。
把实例方法的名称改为QueryDataByName
最后,我们需要带输入参数的查询语句写到方法FindDataByName的RdbCommandText中。代码如下: 

Select "ID","Name" from  Employee Where Name=@name


五、执行
      右击QueryDataByName单击Execute

在弹出的Execute QueryDataByName对话框中,在Value域中输入fans后,单击Execute

  
执行结果如下:

由前面的数据库所知,此demo能正确地查询出想要的结果。

   上一篇 BDC安装
   下一篇 BDC部署到sharepoint站点上


posted on 2008-05-26 18:03  王晓成  阅读(2203)  评论(12编辑  收藏  举报