I am using the following code snippets to insert values using stored procedure. the code is executing successfully开发者_如何学编程 but no record is inserted in DB.
Please suggest with simple example.
**---- stored procedure--------**
Create PROCEDURE [dbo].[SampleInsert]
@id int, @name varchar(50)
AS
BEGIN
insert into test (id, name) values (@id, @name);
END
**------.hbm file-------**
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<sql-query name="Procedure">
exec SampleInsert
:Id,:Name
</sql-query>
</hibernate-mapping>
**--------c# code to insert value using above sp------**
ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
ISession session = sessionFactory.OpenSession();
IQuery query = session.GetNamedQuery("Procedure");
query.SetParameter("Id", "222");
query.SetParameter("Name", "testsp");
query.SetResultTransformer(new NHibernate.Transform.AliasToBeanConstructorResultTransformer(typeof(Procedure).GetConstructors()[0]));
Regards Jcreddy
First, when are you executing the query?
Second, that SP doesn't return anything, what are you adding that ResultTransformer for?
The code should look like this:
session.GetNamedQuery("Procedure")
.SetParameter("Id", "222")
.SetParameter("Name", "testsp")
.ExecuteUpdate()
精彩评论