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


C# VistaDBCommand.ExecuteScalar方法代码示例

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


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

示例1: tgDataResponse

        tgDataResponse IDataProvider.ExecuteScalar(tgDataRequest request)
        {
            tgDataResponse response = new tgDataResponse();
            VistaDBCommand cmd = null;

            try
            {
                cmd = new VistaDBCommand();
                if (request.CommandTimeout != null) cmd.CommandTimeout = request.CommandTimeout.Value;
                if (request.Parameters != null) Shared.AddParameters(cmd, request);

                switch (request.QueryType)
                {
                    case tgQueryType.TableDirect:
                        cmd.CommandType = CommandType.TableDirect;
                        cmd.CommandText = request.QueryText;
                        break;

                    case tgQueryType.StoredProcedure:
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = Shared.CreateFullName(request);
                        break;

                    case tgQueryType.Text:
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = request.QueryText;
                        break;

                    case tgQueryType.DynamicQuery:
                        cmd = QueryBuilder.PrepareCommand(request);
                        break;
                }

                try
                {
                    tgTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);

                    #region Profiling

                    if (sTraceHandler != null)
                    {
                        using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "ExecuteScalar", System.Environment.StackTrace))
                        {
                            try
                            {
                                response.Scalar = cmd.ExecuteScalar();
                            }
                            catch (Exception ex)
                            {
                                esTrace.Exception = ex.Message;
                                throw;
                            }
                        }
                    }
                    else

                    #endregion Profiling

                    {
                        response.Scalar = cmd.ExecuteScalar();
                    }
                }
                finally
                {
                    tgTransactionScope.DeEnlist(cmd);
                }

                if (request.Parameters != null)
                {
                    Shared.GatherReturnParameters(cmd, request, response);
                }
            }
            catch (Exception ex)
            {
                CleanupCommand(cmd);
                response.Exception = ex;
            }

            return response;
        }
开发者ID:BrewDawg,项目名称:Tiraggo,代码行数:80,代码来源:DataProvider.cs

示例2: OnRowUpdated

        protected static void OnRowUpdated(object sender, VistaDBRowUpdatedEventArgs e)
        {
            try
            {
                PropertyCollection props = e.Row.Table.ExtendedProperties;
                if (props.ContainsKey("props"))
                {
                    props = (PropertyCollection)props["props"];
                }

                if (e.Status == UpdateStatus.Continue && (e.StatementType == StatementType.Insert || e.StatementType == StatementType.Update))
                {
                    tgDataRequest request = props["tgDataRequest"] as tgDataRequest;
                    tgEntitySavePacket packet = (tgEntitySavePacket)props["esEntityData"];
                    string source = props["Source"] as string;

                    if (e.StatementType == StatementType.Insert)
                    {
                        if (props.Contains("AutoInc"))
                        {
                            string autoInc = props["AutoInc"] as string;

                            VistaDBCommand cmd = new VistaDBCommand();
                            cmd.Connection = e.Command.Connection;
                            cmd.Transaction = e.Command.Transaction;
                            cmd.CommandText = "SELECT LastIdentity([" + autoInc + "]) FROM [" + source + "]";

                            object o = null;

                            #region Profiling

                            if (sTraceHandler != null)
                            {
                                using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "OnRowUpdated", System.Environment.StackTrace))
                                {
                                    try
                                    {
                                        o = cmd.ExecuteScalar();
                                    }
                                    catch (Exception ex)
                                    {
                                        esTrace.Exception = ex.Message;
                                        throw;
                                    }
                                }
                            }
                            else

                            #endregion Profiling

                            {
                                o = cmd.ExecuteScalar();
                            }

                            if (o != null)
                            {
                                e.Row[autoInc] = o;
                                e.Command.Parameters["@" + autoInc].Value = o;
                            }
                        }

                        if (props.Contains("EntitySpacesConcurrency"))
                        {
                            string esConcurrencyColumn = props["EntitySpacesConcurrency"] as string;
                            packet.CurrentValues[esConcurrencyColumn] = 1;
                        }
                    }

                    if (props.Contains("Timestamp"))
                    {
                        string column = props["Timestamp"] as string;

                        VistaDBCommand cmd = new VistaDBCommand();
                        cmd.Connection = e.Command.Connection;
                        cmd.Transaction = e.Command.Transaction;
                        cmd.CommandText = "SELECT LastTimestamp('" + source + "');";

                        object o = null;

                        #region Profiling

                        if (sTraceHandler != null)
                        {
                            using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "OnRowUpdated", System.Environment.StackTrace))
                            {
                                try
                                {
                                    o = cmd.ExecuteScalar();
                                }
                                catch (Exception ex)
                                {
                                    esTrace.Exception = ex.Message;
                                    throw;
                                }
                            }
                        }
                        else

                        #endregion Profiling

//.........这里部分代码省略.........
开发者ID:BrewDawg,项目名称:Tiraggo,代码行数:101,代码来源:DataProvider.cs

示例3: esDataResponse

        esDataResponse IDataProvider.ExecuteScalar(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();
            VistaDBCommand cmd = null;

            try
            {
                cmd = new VistaDBCommand();
                if (request.CommandTimeout != null) cmd.CommandTimeout = request.CommandTimeout.Value;
                if (request.Parameters != null) Shared.AddParameters(cmd, request);

                switch (request.QueryType)
                {
                    case esQueryType.TableDirect:
                        cmd.CommandType = CommandType.TableDirect;
                        cmd.CommandText = request.QueryText;
                        break;

                    case esQueryType.StoredProcedure:
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = Shared.CreateFullName(request);
                        break;

                    case esQueryType.Text:
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = request.QueryText;
                        break;

                    case esQueryType.DynamicQuery:
                        cmd = QueryBuilder.PrepareCommand(request);
                        break;
                }

                try
                {
                    esTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);
                    response.Scalar = cmd.ExecuteScalar();
                }
                finally
                {
                    esTransactionScope.DeEnlist(cmd);
                }

                if (request.Parameters != null)
                {
                    Shared.GatherReturnParameters(cmd, request, response);
                }
            }
            catch (Exception ex)
            {
                CleanupCommand(cmd);
                response.Exception = ex;
            }

            return response;
        }
开发者ID:stacyjeptha,项目名称:EntitySpaces-Architecture,代码行数:56,代码来源:DataProvider.cs

示例4: OnRowUpdated

        // If it's an Insert we fetch the @@Identity value and stuff it in the proper column
        protected void OnRowUpdated(object sender, VistaDBRowUpdatedEventArgs e)
        {
            try
            {
                if(e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
                {
                    TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr();

                    string[] identityCols = this.GetAutoKeyColumns().Split(';');

                    VistaDBCommand cmd = new VistaDBCommand();

                    foreach(string col in identityCols)
                    {
                        cmd.CommandText = "SELECT LastIdentity([" + col + "]) FROM [" + this.QuerySource + "]";

                        // We make sure we enlist in the ongoing transaction, otherwise, we
                        // would most likely deadlock
                        txMgr.Enlist(cmd, this);
                        object o = cmd.ExecuteScalar(); // Get the Identity Value
                        txMgr.DeEnlist(cmd, this);

                        if(o != null)
                        {
                            e.Row[col] = o;
                        }
                    }

                    e.Row.AcceptChanges();
                }
            }
            catch {}
        }
开发者ID:ivladyka,项目名称:Ekran,代码行数:34,代码来源:VistaDBEntity.cs

示例5: GetDatabaseVersionFunction

 public static string GetDatabaseVersionFunction()
 {
     try
     {
         //To open a SQL connection to VistaDB from within a CLR Proc you must set the connection string to Context connection=true like this....
         //NOTE: We DO want to dispose of this object because we are the ones allocating it
         using (VistaDBConnection conn = new VistaDBConnection("Context Connection=true"))
         {
             conn.Open();
             using (VistaDBCommand command = new VistaDBCommand())
             {
                 command.Connection = conn;
                 command.CommandText = "SELECT @@Version";
                 return Convert.ToString(command.ExecuteScalar());
             }
         }
     }
     catch (Exception e)
     {
         return e.Message;
     }
 }
开发者ID:jasonshort,项目名称:VistaDB-CLR-Proc-Sample,代码行数:22,代码来源:Functions.cs

示例6: GetDatabaseVersionProcedure

 public static int GetDatabaseVersionProcedure(out string versionString )
 {
     try
     {
         //To open a SQL connection to VistaDB from within a CLR Proc you must set the connection string to Context connection=true like this....
         //NOTE: We DO want to dispose of this object because we are the ones allocating it
         using (VistaDBConnection conn = new VistaDBConnection("Context Connection=true"))
         {
             conn.Open();
             using (VistaDBCommand command = new VistaDBCommand())
             {
                 command.Connection = conn;
                 command.CommandText = "SELECT @@Version";
                 versionString = Convert.ToString(command.ExecuteScalar());
                 return 0;
             }
         }
     }
     catch (Exception e)
     {
         throw new ApplicationException("Unable to get the database version due to Application Error", e);
     }
 }
开发者ID:jasonshort,项目名称:VistaDB-CLR-Proc-Sample,代码行数:23,代码来源:Functions.cs

示例7: CallGetDatabaseVersionFunctionSQL

        /// <summary>
        /// Call the Sql Function version to get the database version
        /// </summary>
        public static void CallGetDatabaseVersionFunctionSQL()
        {
            Console.WriteLine("Attempting to execute CLR Function GetDatabaseVersionFunction");
            using (VistaDBConnection connection = new VistaDBConnection(SampleRunner.ConnectionString))
            {
                connection.Open();

                try
                {
                    // Straight forward way to call a function is just using SELECT
                    // You cannot EXEC a SqlFunction, and you cannot set the command here to be a stored proc
                    // Setting this command to a stored proc is a common error, the two are not the same
                    // SqlFunction = SELECT to call
                    // SqlProcdure = EXEC or direct call using StoredProcedure command type
                    using (VistaDBCommand command = new VistaDBCommand())
                    {
                        command.Connection = connection;
                        command.CommandText = "SELECT GetVersionFunction();";
                        // The results are returned as a part of the standard rowset, so we only need to get back the first entry
                        Console.WriteLine(Convert.ToString(command.ExecuteScalar()));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to execute CLR Function GetVersionFunction, Reason: " + e.Message);
                }
            }
        }
开发者ID:jasonshort,项目名称:VistaDB-CLR-Proc-Sample,代码行数:31,代码来源:CallingRoutines.cs

示例8: ExecuteScalar

        /// <summary>
        /// Execute a VistaDBCommand (that returns a 1x1 resultset) against the specified VistaDBTransaction
        /// using the provided parameters.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  int orderCount = (int)ExecuteScalar(trans, CommandType.Text, "Select count(Order) from TableTransaction where ProdId=?", new VistaDBParameter("@prodid", 24));
        /// </remarks>
        /// <param name="transaction">A valid VistaDBTransaction</param>
        /// <param name="commandType">The CommandType (TableDirect, Text)</param>
        /// <param name="commandText">The T-SQL command</param>
        /// <param name="commandParameters">An array of VistaDBParamters used to execute the command</param>
        /// <returns>An object containing the value in the 1x1 resultset generated by the command</returns>
        public static object ExecuteScalar(VistaDBTransaction transaction, CommandType commandType, string commandText, params VistaDBParameter[] commandParameters)
        {
            if( transaction == null ) throw new ArgumentNullException( "transaction" );
            if( transaction != null && transaction.Connection == null ) throw new ArgumentException( "The transaction was rollbacked or commited, please provide an open transaction.", "transaction" );

            // Create a command and prepare it for execution
            VistaDBCommand cmd = new VistaDBCommand();
            bool mustCloseConnection = false;
            PrepareCommand(cmd, (VistaDBConnection)transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);

            // Execute the command & return the results
            object retval = cmd.ExecuteScalar();

            // Detach the VistaDBParameters from the command object, so they can be used again
            cmd.Parameters.Clear();
            return retval;
        }
开发者ID:bnantz,项目名称:Mobile-Data-Access-Application-Block,代码行数:30,代码来源:VistaDB.cs


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