IBatisNet Demo (升级from 1.1)

sqlMap.config, 要修改provider的设置

<providers resource="providers.config"/>

<database>
<provider name="sqlServer2005"/>

<?xml version="1.0" encoding="utf-8"?>     
<sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <settings>
        <setting useStatementNamespaces="false"/>        
    </settings>
    <providers resource="providers.config"/>
    <!-- ==== SqlClient configuration =========    -->
    <!-- Optional ( default ) -->  
    <!-- Rem : If used with a Dao it will be ignored -->    
    <database> 
        <provider name="sqlServer2005"/>
        <dataSource name="oa" connectionString="Data Source=WITDTRM031\SQLSERVER2008;Initial Catalog=CRM;Integrated Security=True"/>        
    </database>   
    <sqlMaps>  
        <sqlMap resource="Maps\UserMap.xml"/>     
    </sqlMaps>     
</sqlMapConfig> 
  
View Code

 

provider.config

将需要用provider改为enabled="true" default="true", Demo中用的是sqlServer2005

<?xml version="1.0" encoding="utf-8"?>
<providers 
xmlns="http://ibatis.apache.org/providers" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<clear/>
    <provider
          name="sqlServer2008"
          enabled="false"
          description="Microsoft SQL Server, provider V4.0.0.0 in framework .NET V4.0"
          assemblyName="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          connectionClass="System.Data.SqlClient.SqlConnection"
          commandClass="System.Data.SqlClient.SqlCommand"
          parameterClass="System.Data.SqlClient.SqlParameter"
          parameterDbTypeClass="System.Data.SqlDbType"
          parameterDbTypeProperty="SqlDbType"
          dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
          commandBuilderClass=" System.Data.SqlClient.SqlCommandBuilder"
          usePositionalParameters = "false"
          useParameterPrefixInSql = "true"
          useParameterPrefixInParameter = "true"
          parameterPrefix="@"
          allowMARS="true"
    />
    
<provider 
      name="sqlServer1.0" 
      description="Microsoft SQL Server, provider V1.0.3300.0 in framework .NET V1.0" 
      enabled="false" 
      assemblyName="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" connectionClass="System.Data.SqlClient.SqlConnection" 
      commandClass="System.Data.SqlClient.SqlCommand" 
      parameterClass="System.Data.SqlClient.SqlParameter" 
      parameterDbTypeClass="System.Data.SqlDbType" 
      parameterDbTypeProperty="SqlDbType" 
      dataAdapterClass="System.Data.SqlClient.SqlDataAdapter" 
      commandBuilderClass="System.Data.SqlClient.SqlCommandBuilder" 
      usePositionalParameters="false" 
      useParameterPrefixInSql="true" 
      useParameterPrefixInParameter="true" 
      parameterPrefix="@"
      allowMARS="false"
  />
<provider 
      name="sqlServer1.1" 
      description="Microsoft SQL Server, provider V1.0.5000.0 in framework .NET V1.1" 
      enabled="false"
      default="true" 
      assemblyName="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
      connectionClass="System.Data.SqlClient.SqlConnection" 
      commandClass="System.Data.SqlClient.SqlCommand" 
      parameterClass="System.Data.SqlClient.SqlParameter" 
      parameterDbTypeClass="System.Data.SqlDbType" 
      parameterDbTypeProperty="SqlDbType" 
      dataAdapterClass="System.Data.SqlClient.SqlDataAdapter" 
      commandBuilderClass="System.Data.SqlClient.SqlCommandBuilder" 
      usePositionalParameters="false" 
      useParameterPrefixInSql="true" 
      useParameterPrefixInParameter="true" 
      parameterPrefix="@"
      allowMARS="false"
  />
<provider
    name="sqlServer2.0"
    enabled="false"
    description="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0" 
    assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
    connectionClass="System.Data.SqlClient.SqlConnection" 
    commandClass="System.Data.SqlClient.SqlCommand"
    parameterClass="System.Data.SqlClient.SqlParameter"
    parameterDbTypeClass="System.Data.SqlDbType"
    parameterDbTypeProperty="SqlDbType"
    dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
    commandBuilderClass=" System.Data.SqlClient.SqlCommandBuilder"
    usePositionalParameters = "false"
    useParameterPrefixInSql = "true"
    useParameterPrefixInParameter = "true" 
    parameterPrefix="@"
    allowMARS="false"
    />
  <provider
     name="sqlServer2005"
     enabled="true"
     default="true"
     description="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0" 
     assemblyName="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     connectionClass="System.Data.SqlClient.SqlConnection" 
     commandClass="System.Data.SqlClient.SqlCommand"
     parameterClass="System.Data.SqlClient.SqlParameter"
     parameterDbTypeClass="System.Data.SqlDbType"
     parameterDbTypeProperty="SqlDbType"
     dataAdapterClass="System.Data.SqlClient.SqlDataAdapter"
     commandBuilderClass=" System.Data.SqlClient.SqlCommandBuilder"
     usePositionalParameters = "false"
     useParameterPrefixInSql = "true"
     useParameterPrefixInParameter = "true" 
     parameterPrefix="@"
     allowMARS="true"
    /> 
</providers>
View Code

 

UserMap.xml (和原来的配置一样)

<?xml version="1.0" encoding="UTF-8"?>
<sqlMap namespace="IbatisTest.Maps" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <alias>
        <typeAlias alias="User" type="IbatisTest.Entity.User"/>
    </alias>
    <resultMaps>
        <resultMap id="UserResult" class="User">
            <result property="Id" column="PK_UserID"/>
            <result property="Name" column="UserName"/>
        </resultMap>
    </resultMaps>
    <statements>
        <select id="GetUser" resultMap="UserResult">
            select
            PK_UserID,
            UserName
            from IBP_T_User
        </select>
    </statements>
</sqlMap>
View Code

 

 DalUser.cs (和原来一样), 可继续使用原来的BaseSqlMapDao.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;

namespace IbatisTest.Sql
{
    public class DalUser : BaseSqlMapDao
    {
        public IList GetUserList()
        {
            return base.ExecuteQueryForList("GetUser", null);
        }
    }
}
View Code

 

下图为目录结构:

 

in page

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) {
                DalUser du = new DalUser();
                GridView1.DataSource = du.GetUserList();
                GridView1.DataBind();
            }
        }

 

Result:

IBatisNet Demo (升级from 1.1),古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。