错误如下: private void button1_Click(object sender, EventArgs e) { var insertProductId = BaseDA.Insert<TUSER>("Insert", new TUSER() { UDept = "aaa", UName = "aaa" }); } 具体配置文件如下: <?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="sqlServer2.0" description="Microsoft SQL Server 7.0/2000/2005, provider V2.0.0.0 in framework .NET V2.0" enabled="true" default="true" 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="@"/> </providers> SQLMAP如下: <?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"/> <setting cacheModelsEnabled="true"/> </settings> <!--db provider配置文件路径--> <providers resource="providers.config"/> <!--db provider类型及连接串--> <database> <provider name="sqlServer2.0" /> <!--<dataSource name="SQLSERVER" connectionString="Data Source=ORCL;Persist Security Info=True;User ID=scott;Password=tiger;Unicode=True" />--> <dataSource name="SQLSERVER" connectionString="Data Source=(local);Initial Catalog=myBatis;User Id=sa;Password=anyqu989125;" /> </database> <!--db与Entity的映射文件--> <sqlMaps> <sqlMap resource="TUser.xml"/> </sqlMaps> </sqlMapConfig> 实体配置如下: <?xml version="1.0" encoding="utf-8" ?> <!--============================================================================ // CAUTION: This file is generated by IBatisNetGen.BatisMap.cst at 2014-10-22 13:59:11 // Any manual editing will be lost in re-generation. //===========================================================================--> <sqlMap namespace="MyBatisDemo" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <alias> <typeAlias alias="TUser" type="MyBatisDemo.TUser" /> </alias> <resultMaps> <resultMap id="FullResultMap" class="TUser"> <result property="UID" column="U_ID" dbType="Int"/> <result property="UName" column="U_Name" dbType="VarChar"/> <result property="UDept" column="U_Dept" dbType="VarChar"/> </resultMap> </resultMaps> <statements> <insert id="Insert" parameterClass="TUSER"> INSERT INTO [dbo].[T_USER] ( [U_ID] , [U_Name] , [U_Dept] ) VALUES ( #UID,dbType=Int# , #UName,dbType=VarChar# , #UDept,dbType=VarChar# ) </insert> </statements> </sqlMap> T_USER类实体如下: using System; using System.Collections.Generic; using System.Text; namespace MyBatisDemo { //============================================================================== /// <summary><c>TUSER</c> Business Object.</summary> [Serializable] public partial class TUSER { #region UID private Int32 m_uID; /// <summary>Gets or sets UID</summary> public Int32 UID { get { return m_uID; } set { m_uID = value; } } #endregion #region UName private String m_uName; /// <summary>Gets or sets UName</summary> public String UName { get { return m_uName; } set { m_uName = value; } } #endregion #region UDept private String m_uDept; /// <summary>Gets or sets UDept</summary> public String UDept { get { return m_uDept; } set { m_uDept = value; } } #endregion } } 求高手指导一下! |
|
40分
#1 |
很明显是productmap.xml文件里面的问题,语法错误,xml分析没有通过。
你点击“查看详细信息”,看看里面的innerexception属性,里面有更具体的信息。 目测这些地方逗号有误:#UName,dbType=VarChar# 改成: #UName:VarChar#看看 |
#2 |
楼上所说的配置非自己写的,而是从Codesmith生成的,难道真的是这里错了!我试一下!
|
#3 |
试过了,还是不好使。查看详细错误发现如下:
在解决方案中搜索未发现这个文件 不知道这个ProductMap.xml这个是什么文件?有什么用。需要如何配置?放在项目的什么位置? |
#4 |
现在提示:未将对象引用设置到对象的实例,请问如何解决?
TUser.xml如下: <?xml version="1.0" encoding="utf-8" ?> <!--============================================================================ // CAUTION: This file is generated by IBatisNetGen.BatisMap.cst at 2014-10-22 13:59:11 // Any manual editing will be lost in re-generation. //===========================================================================--> <sqlMap namespace="MyBatisDemo" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <alias> <typeAlias alias="TUser" type="MyBatisDemo.TUser" /> </alias> <resultMaps> <resultMap id="FullResultMap" class="TUser"> <result property="UID" column="U_ID" dbType="Int"/> <result property="UName" column="U_Name" dbType="VarChar"/> <result property="UDept" column="U_Dept" dbType="VarChar"/> </resultMap> </resultMaps> <statements> <insert id="Insert_User" parameterClass="TUser"> INSERT INTO [dbo].[T_USER] ( [U_Name] , [U_Dept] ) VALUES ( #UName# , #UDept# ) </insert> </statements> </sqlMap> |
#5 |
你这个站点 放到服务器上占用cpu 高吗
|