VS2005引用iBatis綁定到GridView

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的參數.

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章