NHibernate1.2 中 执行“存储过程”
来源:互联网 发布:巨潮数据库 编辑:程序博客网 时间:2024/05/19 09:13
using NHibernate.Engine;
using NHibernate;
namespace DataAccess
{
public class UserAccess
{
public UserAccess()
{
cfg.AddAssembly("Entitys");
//session = cfg.BuildSessionFactory().OpenSession();
}
private NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
private ISession session = null;
private ITransaction tran = null;
/// <summary>
/// NHibernate 调用存储过程
/// </summary>
/// <returns></returns>
public ArrayList ExeProc()
{
ArrayList list = new ArrayList();
ISessionFactoryImplementor imp = (ISessionFactoryImplementor)cfg.BuildSessionFactory();
IDbConnection conn = imp.ConnectionProvider.GetConnection();
IDbCommand cmd = imp.ConnectionProvider.GetConnection().CreateCommand();
try
{
cmd.CommandText = "TestProc"; //存储过程名
cmd.CommandType = System.Data.CommandType.StoredProcedure;
IDbDataParameter parameter = cmd.CreateParameter();
parameter.ParameterName = "id"; //需要的参数
parameter.Value = 3; //为参数赋值
cmd.Parameters.Add(parameter);
cmd.Connection = conn; //设置连接
IDataReader read= cmd.ExecuteReader();
while (read.Read())
{
UserTest collection = new UserTest();
collection.age = read.GetValue(0).ToString();
collection.id = read.GetValue(1).ToString();
collection.LastTime = read.GetValue(2).ToString();
collection.TureName= read.GetValue(3).ToString();
list.Add(collection);
}
}
catch (Exception ex)
{
this.m_error = ex.Message;
}
finally
{
imp.CloseConnection(conn);
}
return list;
}
}
-----------展现层调用------------
protected void Button8_Click(object sender, EventArgs e)
{
list = UserTools.ExeProc();
this.GridView1.DataSource = list;
this.GridView1.DataBind();
this.Label2.Text = UserTools.Error;
}
--------------sql 存储过程创建方法--------------------
--创建存储过程
alter proc TestProc
(
@id int
)
as
(
select * from login where id=@id
)
--测试存储过程
exec TestProc 3
- NHibernate1.2 中 执行“存储过程”
- NHibernate1.2 执行多表查询
- NHibernate1.2 执行sql 邦定GridView!!!!!!!!!!!!!
- 在存储过程中执行存储过程
- oracle中执行存储过程
- oracle中执行存储过程
- sqlplus中执行存储过程
- sqlplus中执行存储过程
- C#中执行存储过程
- c#中执行存储过程
- 存储过程中执行DDL
- VC中执行存储过程
- dal中执行存储过程
- Java中执行存储过程
- ADO执行存储过程2
- 在VB中执行存储过程!
- 在ASP中执行存储过程
- ASP中如何执行存储过程?
- 中国象棋.汉诺塔游戏.计算器.记事本.俄罗斯方块
- 标准模板库(STL)介绍
- 热烈庆祝十七大的召开
- MS SQL Server日期计算
- JSP连接SQL Server 2000系统配置
- NHibernate1.2 中 执行“存储过程”
- 什么是cookie欺骗
- Memo/RichEdit行列定位
- 面向对象的NHibernate数据查询语言-HQL
- 释放资源问题(图片)
- Visual Basic6.0中Any类型 迁至 Visual Basic 2005 中的变化
- discuz!Nt整合日记。
- 微软正版验证的处理方法
- QWERTY,QWERTZ和AZERTY