当前位置: 首页>>代码示例>>C#>>正文


C# IDalSession.OpenConnection方法代码示例

本文整理汇总了C#中IDalSession.OpenConnection方法的典型用法代码示例。如果您正苦于以下问题:C# IDalSession.OpenConnection方法的具体用法?C# IDalSession.OpenConnection怎么用?C# IDalSession.OpenConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDalSession的用法示例。


在下文中一共展示了IDalSession.OpenConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InternalDiscoverSpParameterSet

        /// <summary>
        /// Discover at run time the appropriate set of Parameters for a stored procedure
        /// </summary>
		/// <param name="session">An IDalSession object</param>
		/// <param name="spName">Name of the stored procedure.</param>
        /// <param name="includeReturnValueParameter">if set to <c>true</c> [include return value parameter].</param>
        /// <returns>The stored procedure parameters.</returns>
		private IDataParameter[] InternalDiscoverSpParameterSet(IDalSession session, string spName, 
            bool includeReturnValueParameter)
		{
			using (IDbCommand cmd = session.CreateCommand(CommandType.StoredProcedure))
			{
				cmd.CommandText = spName;

			    // The session connection object is always created but the connection is not alwys open
			    // so we try to open it in case.
				session.OpenConnection();

				DeriveParameters(session.DataSource.DbProvider, cmd);

				if (cmd.Parameters.Count > 0) {
					IDataParameter firstParameter = (IDataParameter)cmd.Parameters[0];
					if (firstParameter.Direction == ParameterDirection.ReturnValue) {
						if (!includeReturnValueParameter) {
							cmd.Parameters.RemoveAt(0);
						}
					}	
				}


				IDataParameter[] discoveredParameters = new IDataParameter[cmd.Parameters.Count];
				cmd.Parameters.CopyTo(discoveredParameters, 0);
				return discoveredParameters;
			}
		}
开发者ID:techvenky,项目名称:mybatisnet,代码行数:35,代码来源:DBHelperParameterCache.cs

示例2: InternalDiscoverSpParameterSet

        /// <summary>
        /// Discover at run time the appropriate set of Parameters for a stored procedure
        /// </summary>
		/// <param name="session">An IDalSession object</param>
		/// <param name="spName">Name of the stored procedure.</param>
        /// <param name="includeReturnValueParameter">if set to <c>true</c> [include return value parameter].</param>
        /// <returns>The stored procedure parameters.</returns>
		private IDataParameter[] InternalDiscoverSpParameterSet(IDalSession session, string spName, 
            bool includeReturnValueParameter)
		{
#if !dotnet2
        	// SqlCommandBuilder.DeriveParameters(<command>) does not support transactions. 
        	// If the command is within a transaction, you will get the following error: 
			// “SqlCommandBuilder Execute requires the command to have a transaction object 
        	// when the connection assigned to the command is in a pending local transaction” 
        	// even when the command object does in fact have a transaction object. 
			using (IDbConnection connection = session.DataSource.DbProvider.CreateConnection())
			{
				connection.ConnectionString = session.DataSource.ConnectionString;
				connection.Open();
				using (IDbCommand cmd = connection.CreateCommand())
				{
				cmd.CommandType = CommandType.StoredProcedure;
#else
				using (IDbCommand cmd = session.CreateCommand(CommandType.StoredProcedure))
				{
#endif
					cmd.CommandText = spName;

				    // The session connection object is always created but the connection is not alwys open
				    // so we try to open it in case.
					session.OpenConnection();

					DeriveParameters(session.DataSource.DbProvider, cmd);

					if (cmd.Parameters.Count > 0) {
						IDataParameter firstParameter = (IDataParameter)cmd.Parameters[0];
						if (firstParameter.Direction == ParameterDirection.ReturnValue) {
							if (!includeReturnValueParameter) {
								cmd.Parameters.RemoveAt(0);
							}
						}	
					}


					IDataParameter[] discoveredParameters = new IDataParameter[cmd.Parameters.Count];
					cmd.Parameters.CopyTo(discoveredParameters, 0);
					return discoveredParameters;
				}
#if !dotnet2
			}
#endif
		}
开发者ID:hejiquan,项目名称:iBATIS_2010,代码行数:53,代码来源:DBHelperParameterCache.cs


注:本文中的IDalSession.OpenConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。