當前位置: 首頁>>代碼示例>>C#>>正文


C# NpgsqlCommand.ExecuteScalarAsync方法代碼示例

本文整理匯總了C#中Npgsql.NpgsqlCommand.ExecuteScalarAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# NpgsqlCommand.ExecuteScalarAsync方法的具體用法?C# NpgsqlCommand.ExecuteScalarAsync怎麽用?C# NpgsqlCommand.ExecuteScalarAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Npgsql.NpgsqlCommand的用法示例。


在下文中一共展示了NpgsqlCommand.ExecuteScalarAsync方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Scalar

 public async Task Scalar()
 {
     using (var conn = OpenConnection())
     using (var cmd = new NpgsqlCommand("SELECT 1", conn)) {
         Assert.That(await cmd.ExecuteScalarAsync(), Is.EqualTo(1));
     }
 }
開發者ID:ArsenShnurkov,項目名稱:npgsql,代碼行數:7,代碼來源:AsyncTests.cs

示例2: ExecuteScalarAsync

 protected async Task<object> ExecuteScalarAsync(string sql, NpgsqlConnection conn = null)
 {
     if (conn == null)
         conn = Conn;
     using (var cmd = new NpgsqlCommand(sql, conn))
         return await cmd.ExecuteScalarAsync();
 }
開發者ID:Tradioyes,項目名稱:Npgsql,代碼行數:7,代碼來源:TestBase.cs

示例3: Scalar

 public async void Scalar()
 {
     using (var cmd = new NpgsqlCommand("SELECT 1", Conn)) {
         Assert.That(await cmd.ExecuteScalarAsync(), Is.EqualTo(1));
     }
 }
開發者ID:Emill,項目名稱:Npgsql,代碼行數:6,代碼來源:AsyncTests.cs

示例4: AddDriverAsync

		public async Task<int> AddDriverAsync(Driver theDriver)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aCommand = new NpgsqlCommand(
					"Insert into driver (firstname, lastname, address, city, state, postalcode, country, licensenumber, licensestate, customerid) VALUES (:value1, :value2, :value3, :value4, :value5, :value6, :value7, :value8, :value9, :value10) RETURNING id", Connection);
				aCommand.Parameters.AddWithValue("value1", theDriver.FirstName);
				aCommand.Parameters.AddWithValue("value2", theDriver.LastName);
				aCommand.Parameters.AddWithValue("value3", theDriver.Address);
				aCommand.Parameters.AddWithValue("value4", theDriver.City);
				aCommand.Parameters.AddWithValue("value5", theDriver.State);
				aCommand.Parameters.AddWithValue("value6", theDriver.PostalCode);
				aCommand.Parameters.AddWithValue("value7", theDriver.Country);
				aCommand.Parameters.AddWithValue("value8", theDriver.LicenseNumber);
				aCommand.Parameters.AddWithValue("value9", theDriver.LicenseState);
				aCommand.Parameters.AddWithValue("value10", theDriver.CustomerId);

				// returns the id from the SELECT, RETURNING sql statement above
				return Convert.ToInt32(await aCommand.ExecuteScalarAsync().ConfigureAwait(false));
			}
			catch (NpgsqlException)
			{
				return 0;
			}
			catch (InvalidOperationException)
			{
				return 0;
			}
			catch (SqlException)
			{
				return 0;
			}
			catch (ConfigurationErrorsException)
			{
				return 0;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
開發者ID:gblosser,項目名稱:FullStackReference,代碼行數:44,代碼來源:DriverRepository.cs

示例5: AddCustomerAsync

		public async Task<int> AddCustomerAsync(Customer theCustomer)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aCommand = new NpgsqlCommand(
					"Insert into customer (name, allowsadditionaldrivers, allowsadditions, hasmaxrentaldays, maxrentaldays) VALUES (:value1, :value2, :value3, :value4, :value5) RETURNING id", Connection);
				aCommand.Parameters.AddWithValue("value1", theCustomer.Name);
				aCommand.Parameters.AddWithValue("value2", theCustomer.AllowsAdditionalDrivers);
				aCommand.Parameters.AddWithValue("value3", theCustomer.AllowsAdditions);
				aCommand.Parameters.AddWithValue("value4", theCustomer.HasMaxRentalDays);
				aCommand.Parameters.AddWithValue("value5", theCustomer.MaxRentalDays);

				// returns the id from the SELECT, RETURNING sql statement above
				return Convert.ToInt32(await aCommand.ExecuteScalarAsync().ConfigureAwait(false));
			}
			catch (NpgsqlException)
			{
				return 0;
			}
			catch (InvalidOperationException)
			{
				return 0;
			}
			catch (SqlException)
			{
				return 0;
			}
			catch (ConfigurationErrorsException)
			{
				return 0;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
開發者ID:gblosser,項目名稱:FullStackReference,代碼行數:39,代碼來源:CustomerRepository.cs

示例6: TestConnectionAsync

 /// <summary>
 /// Tests the connection asynchronously.
 /// </summary>
 /// <returns></returns>
 public override async Task TestConnectionAsync()
 {
     using (var con = await CreateConnectionAsync())
     using (var cmd = new NpgsqlCommand("SELECT 1", con))
         await cmd.ExecuteScalarAsync();
 }
開發者ID:docevaad,項目名稱:Chain,代碼行數:10,代碼來源:PostgreSqlDataSource.cs

示例7: AddLocationAsync

		public async Task<int> AddLocationAsync(Location theLocation)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aCommand = new NpgsqlCommand(
					"Insert into location (customerid, name, address, city, state, postalcode, country, latitude, longitude) VALUES (:value1, :value2, :value3, :value4, :value5, :value6, :value7, :value8, :value9) RETURNING id", Connection);
				aCommand.Parameters.AddWithValue("value1", theLocation.CustomerId);
				aCommand.Parameters.AddWithValue("value2", theLocation.Name);
				aCommand.Parameters.AddWithValue("value3", theLocation.Address);
				aCommand.Parameters.AddWithValue("value4", theLocation.City);
				aCommand.Parameters.AddWithValue("value5", theLocation.State);
				aCommand.Parameters.AddWithValue("value6", theLocation.PostalCode);
				aCommand.Parameters.AddWithValue("value7", theLocation.Country);
				aCommand.Parameters.AddWithValue("value8", theLocation.Latitude);
				aCommand.Parameters.AddWithValue("value9", theLocation.Longitude);

				// returns the id from the SELECT, RETURNING sql statement above
				return Convert.ToInt32(await aCommand.ExecuteScalarAsync().ConfigureAwait(false));
			}
			catch (NpgsqlException)
			{
				return 0;
			}
			catch (InvalidOperationException)
			{
				return 0;
			}
			catch (SqlException)
			{
				return 0;
			}
			catch (ConfigurationErrorsException)
			{
				return 0;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
開發者ID:gblosser,項目名稱:FullStackReference,代碼行數:43,代碼來源:LocationRepository.cs

示例8: AddUserAsync

		public async Task<int> AddUserAsync(User theUser)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aCommand = new NpgsqlCommand(
					"Insert into appuser (firstname, lastname, email, customerid, isemployee) VALUES (:value1, :value2, :value3, :value4, :value5) RETURNING id", Connection);
				aCommand.Parameters.AddWithValue("value1", theUser.FirstName);
				aCommand.Parameters.AddWithValue("value2", theUser.LastName);
				aCommand.Parameters.AddWithValue("value3", theUser.Email);
				aCommand.Parameters.AddWithValue("value4", theUser.CustomerId);
				aCommand.Parameters.AddWithValue("value5", theUser.IsEmployee);

				// returns the id from the SELECT, RETURNING sql statement above
				return Convert.ToInt32(await aCommand.ExecuteScalarAsync().ConfigureAwait(false));
			}
			catch (NpgsqlException)
			{
				return 0;
			}
			catch (InvalidOperationException)
			{
				return 0;
			}
			catch (SqlException)
			{
				return 0;
			}
			catch (ConfigurationErrorsException)
			{
				return 0;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
開發者ID:gblosser,項目名稱:FullStackReference,代碼行數:39,代碼來源:UserRepository.cs

示例9: AddAutomobileAsync

		public async Task<int> AddAutomobileAsync(Automobile theAutomobile)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aCommand = new NpgsqlCommand(
					"Insert into automobile (vin, vehiclenumber, name, class, style, color, manufacturer, model, code, locationid) VALUES (:value1, :value2, :value3, :value4, :value5, :value6, :value7, :value8, :value9, :value10) RETURNING id", Connection);
				aCommand.Parameters.AddWithValue("value1", theAutomobile.VIN);
				aCommand.Parameters.AddWithValue("value2", theAutomobile.VehicleNumber);
				aCommand.Parameters.AddWithValue("value3", theAutomobile.Name);
				aCommand.Parameters.AddWithValue("value4", theAutomobile.Class);
				aCommand.Parameters.AddWithValue("value5", theAutomobile.Style);
				aCommand.Parameters.AddWithValue("value6", theAutomobile.Color);
				aCommand.Parameters.AddWithValue("value7", theAutomobile.Manufacturer);
				aCommand.Parameters.AddWithValue("value8", theAutomobile.Model);
				aCommand.Parameters.AddWithValue("value9", theAutomobile.Code);
				aCommand.Parameters.AddWithValue("value10", theAutomobile.LocationId);

				// returns the id from the SELECT, RETURNING sql statement above
				return Convert.ToInt32(await aCommand.ExecuteScalarAsync().ConfigureAwait(false));
			}
			catch (NpgsqlException)
			{
				return 0;
			}
			catch (InvalidOperationException)
			{
				return 0;
			}
			catch (SqlException)
			{
				return 0;
			}
			catch (ConfigurationErrorsException)
			{
				return 0;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
開發者ID:gblosser,項目名稱:FullStackReference,代碼行數:44,代碼來源:AutomobileRepository.cs


注:本文中的Npgsql.NpgsqlCommand.ExecuteScalarAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。