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


C# OleDbCommand.ExecuteScalarAsync方法代码示例

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


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

示例1: NrRows

        public static async Task<long> NrRows(string pathToExcel,string SheetName= "[Sheet1$]")
        {
            using (var m = new OleDbConnection())
            {
                m.ConnectionString = ExcelHelpers.BuildExcelConnectionString(pathToExcel, false);
                await m.OpenAsync();
                var query = @"Select count(*) From " + SheetName;
                using (var cmd = new OleDbCommand(query, m))
                {
                    var dr = await cmd.ExecuteScalarAsync();
                    return long.Parse(dr.ToString());
                    
                }

            }
        }
开发者ID:ignatandrei,项目名称:RomaniaOpenData,代码行数:16,代码来源:ExcelHelpers.cs

示例2: TestConnectionAsync

 /// <summary>
 /// Tests the connection asynchronously.
 /// </summary>
 /// <returns></returns>
 public override async Task TestConnectionAsync()
 {
     using (var con = await CreateConnectionAsync())
     using (var cmd = new OleDbCommand("SELECT 1", con))
         await cmd.ExecuteScalarAsync();
 }
开发者ID:docevaad,项目名称:Chain,代码行数:10,代码来源:OleDbSqlServerDataSource.cs

示例3: LoadFileAsync

        /// <summary>
        /// Receives file bytes from database by given file name
        /// </summary>
        /// <param name="name">Name of file to load</param>
        public static async Task<byte[]> LoadFileAsync(string name)
        {
            string connectionString = defaultConnectionString;

            using (var connection = new System.Data.OleDb.OleDbConnection(connectionString))
            {
                try
                {
                    await connection.OpenAsync();

                    string query = "SELECT FileData FROM Files WHERE name = @name;";

                    using (var command = new System.Data.OleDb.OleDbCommand(query, connection))
                    {
                        command.Parameters.AddWithValue("@name", name);

                        return (byte[])await command.ExecuteScalarAsync();
                    }
                }
                catch(Exception ex)
                {
                    TextEditor.WPFMessageBoxException(ex);
                    return null;
                }
            }
        }
开发者ID:duskjet,项目名称:wpf-texteditor-with-db,代码行数:30,代码来源:FileRepository.cs

示例4: ReloadAsync

 internal async Task ReloadAsync(OleDbConnection connection, OleDbTransaction transaction)
 {
     using (var cmd = new OleDbCommand("SELECT @@Options") { Connection = connection, Transaction = transaction })
         m_Options = (int)(await cmd.ExecuteScalarAsync());
 }
开发者ID:docevaad,项目名称:Chain,代码行数:5,代码来源:SqlServerEffectiveSettings.cs

示例5: ExecuteAsync

        /// <summary>
        /// Executes the specified operation asynchronously.
        /// </summary>
        /// <param name="executionToken"></param>
        /// <param name="implementation"></param>
        /// <param name="cancellationToken"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        protected override async Task<int?> ExecuteAsync(CommandExecutionToken<OleDbCommand, OleDbParameter> executionToken, CommandImplementationAsync<OleDbCommand> implementation, CancellationToken cancellationToken, object state)
        {
            if (executionToken == null)
                throw new ArgumentNullException("executionToken", "executionToken is null.");
            if (implementation == null)
                throw new ArgumentNullException("implementation", "implementation is null.");
            var currentToken = executionToken as AccessCommandExecutionToken;
            if (currentToken == null)
                throw new ArgumentNullException("executionToken", "only AccessCommandExecutionToken is supported.");

            var startTime = DateTimeOffset.Now;

            try
            {
                using (var con = await CreateConnectionAsync(cancellationToken).ConfigureAwait(false))
                {
                    int? rows = null;
                    while (currentToken != null)
                    {
                        OnExecutionStarted(currentToken, startTime, state);
                        using (var cmd = new OleDbCommand())
                        {
                            cmd.Connection = con;
                            if (DefaultCommandTimeout.HasValue)
                                cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                            cmd.CommandText = currentToken.CommandText;
                            cmd.CommandType = currentToken.CommandType;
                            foreach (var param in currentToken.Parameters)
                                cmd.Parameters.Add(param);

                            currentToken.ApplyCommandOverrides(cmd);

                            if (currentToken.ExecutionMode == AccessCommandExecutionMode.Materializer)
                                rows = await implementation(cmd);
                            else if (currentToken.ExecutionMode == AccessCommandExecutionMode.ExecuteScalarAndForward)
                                currentToken.ForwardResult(await cmd.ExecuteScalarAsync());
                            else
                                rows = await cmd.ExecuteNonQueryAsync();
                            executionToken.RaiseCommandExecuted(cmd, rows);
                            OnExecutionFinished(currentToken, startTime, DateTimeOffset.Now, rows, state);
                        }
                        currentToken = currentToken.NextCommand;
                    }
                    return rows;
                }
            }
            catch (Exception ex)
            {
                if (cancellationToken.IsCancellationRequested) //convert Exception into a OperationCanceledException 
                {
                    var ex2 = new OperationCanceledException("Operation was canceled.", ex, cancellationToken);
                    OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex2, state);
                    throw ex2;
                }
                else
                {
                    OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                    throw;
                }
            }
        }
开发者ID:docevaad,项目名称:Chain,代码行数:69,代码来源:AccessDataSource.cs


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