VS2005引用iBatis绑定到GridView

来源:互联网 发布:考研数学汤家凤 知乎 编辑:程序博客网 时间:2024/05/21 01:30

1、添加引用:

   

2、添加config文件:providers.config, SqlMap.config

     providers.config里提供数据库的相关信息,如下:

我这里只使用了SQLServer2000。

  SqlMap.config里添加数据库的链接字符串和使用的xml文件。

3、添加XML文件

     XML文件里是使用到的SQL语句和类到数据库的反射。如上在Sql.Map文件中我使用到了两个.xml文件。

     StandardTech.xml文件如下:

此文件中只有一个select语句“select SID,StandardNo,StandardName,Material,Type  from V_JjCardIndex where type=#type#  order by StandardNo”

如果要添加其他的sql语句,直接在<statements></statements>中间加即可。

在<select></select>里有一个id,便于应用程序使用对应的sql语句,resultMap跟前面的<resultMap>对应,parameterClass说明参数的类型。

resultMap将数据库里的表或视图跟创建的某个类对应,如此处就对应到class=“StandardTech”,property是StandardTech类的属性,column是对应的数据库里的字段。

4、.cs文件应用

  如要将上面  StandardTech.xml文件里的select语句获取的结果绑定到一个GridView,代码如下:

Mapper在添加了 using IBatisNet.DataMapper之后就有了。QueryForList的两个参数:

-- “StandardTech.SelectAllStandardTech”是指StandardTech.xml文件里的信息,StandardTech是<sqlMap>里的namespace,SelectAllStandardTech是<select>的id.

-- 0 是传进到SelectAllStandardTech的参数.

 

 

原创粉丝点击