本文整理汇总了C#中Npgsql.NpgsqlCommand类的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlCommand类的具体用法?C# NpgsqlCommand怎么用?C# NpgsqlCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NpgsqlCommand类属于Npgsql命名空间,在下文中一共展示了NpgsqlCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getListGrilleRistourne
public static List<GrilleRabais> getListGrilleRistourne(String query)
{
NpgsqlConnection con = Connexion.Connection();
try
{
List<GrilleRabais> l = new List<GrilleRabais>();
NpgsqlCommand Lcmd = new NpgsqlCommand(query, con);
NpgsqlDataReader lect = Lcmd.ExecuteReader();
if (lect.HasRows)
{
while (lect.Read())
{
GrilleRabais a = new GrilleRabais();
a.Id = Convert.ToInt64(lect["id"].ToString());
a.Nature = lect["nature_montant"].ToString();
a.Minimal = (Double)((lect["montant_minimal"] != null) ? ((!lect["montant_minimal"].ToString().Trim().Equals("")) ? lect["montant_minimal"] : 0) : 0);
a.Maximal = (Double)((lect["montant_maximal"] != null) ? ((!lect["montant_maximal"].ToString().Trim().Equals("")) ? lect["montant_maximal"] : 0) : 0);
a.Montant = (Double)((lect["montant_ristourne"] != null) ? ((!lect["montant_ristourne"].ToString().Trim().Equals("")) ? lect["montant_ristourne"] : 0) : 0);
a.Update = true;
l.Add(a);
}
lect.Close();
}
return l;
}
catch (NpgsqlException e)
{
Messages.Exception(e);
return null;
}
finally
{
Connexion.Deconnection(con);
}
}
示例2: GetMenuTable
public static DataTable GetMenuTable(int parentMenuId, short level, int userId, int officeId, string culture)
{
if (userId.Equals(0))
{
return null;
}
if (officeId.Equals(0))
{
return null;
}
string sql = "SELECT * FROM policy.get_menu(@UserId, @OfficeId, @Culture) WHERE parent_menu_id is null ORDER BY menu_id;";
if (parentMenuId > 0)
{
sql = "SELECT * FROM policy.get_menu(@UserId, @OfficeId, @Culture) WHERE [email protected] AND [email protected] ORDER BY menu_id;";
}
using (NpgsqlCommand command = new NpgsqlCommand(sql))
{
command.Parameters.AddWithValue("@UserId", userId);
command.Parameters.AddWithValue("@OfficeId", officeId);
command.Parameters.AddWithValue("@Culture", culture);
if (parentMenuId > 0)
{
command.Parameters.AddWithValue("@ParentMenuId", parentMenuId);
command.Parameters.AddWithValue("@Level", level);
}
return DbOperations.GetDataTable(command);
}
}
示例3: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
string checks;
string checkw;
string id_sali = DropDownList1.SelectedItem.ToString();
string id_wyp = DropDownList2.SelectedItem.ToString();
NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgres;Password=projekt;Database=projekt;");
conn.Open();
NpgsqlCommand check1 = new NpgsqlCommand("select id_sali from wyp_sali where id_sali = '" + id_sali + "'", conn);
NpgsqlCommand check2 = new NpgsqlCommand("select id_wyp from wyp_sali where id_sali = '" + id_sali + "'and id_wyp = '" + id_wyp + "'", conn);
checks = (String)check1.ExecuteScalar();
checkw = (String)check2.ExecuteScalar();
if (checks == id_sali && checkw == id_wyp)
{
Label2.Text = "";
Label3.Text = "Wyposażenie jest już przypisane do sali!";
}
else if (checkw != id_wyp)
{
NpgsqlCommand add = new NpgsqlCommand("insert into wyp_sali values ('" + id_wyp + "', '" + id_sali + "')", conn);
add.ExecuteScalar();
conn.Close();
Label2.Text = "Dodano wyposażenie do sali!";
Label3.Text = "";
}
}
示例4: Long
public void Long([Values(CommandBehavior.Default, CommandBehavior.SequentialAccess)] CommandBehavior behavior)
{
var builder = new StringBuilder("ABCDEééé", Conn.BufferSize);
builder.Append('X', Conn.BufferSize);
var expected = builder.ToString();
ExecuteNonQuery("CREATE TEMP TABLE data (name TEXT)");
var cmd = new NpgsqlCommand(@"INSERT INTO data (name) VALUES (@p)", Conn);
cmd.Parameters.Add(new NpgsqlParameter("p", expected));
cmd.ExecuteNonQuery();
const string queryText = @"SELECT name, 'foo', name, name, name, name FROM data";
cmd = new NpgsqlCommand(queryText, Conn);
var reader = cmd.ExecuteReader(behavior);
reader.Read();
var actual = reader[0];
Assert.That(actual, Is.EqualTo(expected));
if (IsSequential(behavior))
Assert.That(() => reader[0], Throws.Exception.TypeOf<InvalidOperationException>(), "Seek back sequential");
else
Assert.That(reader[0], Is.EqualTo(expected));
Assert.That(reader.GetString(1), Is.EqualTo("foo"));
Assert.That(reader.GetFieldValue<string>(2), Is.EqualTo(expected));
Assert.That(reader.GetValue(3), Is.EqualTo(expected));
Assert.That(reader.GetFieldValue<string>(4), Is.EqualTo(expected));
Assert.That(reader.GetFieldValue<char[]>(5), Is.EqualTo(expected.ToCharArray()));
}
示例5: Get
// GET api/values
public IEnumerable<string> Get()
{
// return new string[] { "value1", "value2" };
var result = new List<string>();
using (var conn = new NpgsqlConnection())
{
conn.ConnectionString = "PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;DATABASE=pdtgis;HOST=localhost;USER ID=postgres;PASSWORD=morty";
conn.Open();
using (var cmd = new NpgsqlCommand())
{
cmd.Connection = conn;
cmd.CommandText =
"SELECT name,amenity, ST_AsGeoJson(way) FROM planet_osm_point WHERE amenity = \'pub\' LIMIT 10;";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
result.Add(reader.GetString(2));
}
}
}
}
return result;
}
示例6: PostTransaction
public static long PostTransaction(string catalog, long transactionMasterId, DateTime valueDate, int officeId, int userId, long loginId, int storeId, string partyCode, int priceTypeId, string referenceNumber, string statementReference, Collection<StockDetail> details, Collection<Attachment> attachments)
{
string detail = StockMasterDetailHelper.CreateStockMasterDetailParameter(details);
string attachment = AttachmentHelper.CreateAttachmentModelParameter(attachments);
string sql = string.Format(CultureInfo.InvariantCulture, "SELECT * FROM transactions.post_purchase_return(@TransactionMasterId::bigint, @OfficeId::integer, @UserId::integer, @LoginId::bigint, @ValueDate::date, @StoreId::integer, @PartyCode::national character varying(12), @PriceTypeId::integer, @ReferenceNumber::national character varying(24), @StatementReference::text, ARRAY[{0}], ARRAY[{1}]);", detail, attachment);
using (NpgsqlCommand command = new NpgsqlCommand(sql))
{
command.Parameters.AddWithValue("@TransactionMasterId", transactionMasterId);
command.Parameters.AddWithValue("@OfficeId", officeId);
command.Parameters.AddWithValue("@UserId", userId);
command.Parameters.AddWithValue("@LoginId", loginId);
command.Parameters.AddWithValue("@ValueDate", valueDate);
command.Parameters.AddWithValue("@StoreId", storeId);
command.Parameters.AddWithValue("@PartyCode", partyCode);
command.Parameters.AddWithValue("@PriceTypeId", priceTypeId);
command.Parameters.AddWithValue("@ReferenceNumber", referenceNumber);
command.Parameters.AddWithValue("@StatementReference", statementReference);
command.Parameters.AddRange(StockMasterDetailHelper.AddStockMasterDetailParameter(details).ToArray());
command.Parameters.AddRange(AttachmentHelper.AddAttachmentParameter(attachments).ToArray());
long tranId = Conversion.TryCastLong(DbOperation.GetScalarValue(catalog, command));
return tranId;
}
}
示例7: GetDisplayFields
/// <param name="catalog">The name of the database on which queries are being executed to.</param>
public static IEnumerable<DisplayField> GetDisplayFields(string catalog)
{
List<DisplayField> displayFields = new List<DisplayField>();
const string sql = "SELECT employee_type_id AS key, employee_type_code || ' (' || employee_type_name || ')' as value FROM hrm.employee_types;";
using (NpgsqlCommand command = new NpgsqlCommand(sql))
{
using (DataTable table = DbOperation.GetDataTable(catalog, command))
{
if (table?.Rows == null || table.Rows.Count == 0)
{
return displayFields;
}
foreach (DataRow row in table.Rows)
{
if (row != null)
{
DisplayField displayField = new DisplayField
{
Key = row["key"].ToString(),
Value = row["value"].ToString()
};
displayFields.Add(displayField);
}
}
}
}
return displayFields;
}
示例8: BuildAdditionalFromDataBaseData
public static TestReferralSurvey BuildAdditionalFromDataBaseData(string idReferral)
{
using (NpgsqlConnection connection = Global.GetSqlConnection())
{
string findPatient = "SELECT id_survey_organ, survey_comment, id_survey_type FROM public.referral WHERE id_referral = '" + idReferral + "' ORDER BY id_referral DESC LIMIT 1";
NpgsqlCommand person = new NpgsqlCommand(findPatient, connection);
using (NpgsqlDataReader personFromDataBase = person.ExecuteReader())
{
Survey p = new Survey();
while (personFromDataBase.Read())
{
//что делать с DateSpecified и Мисами?
if (personFromDataBase["survey_comment"] != DBNull.Value)
p.Comment = Convert.ToString(personFromDataBase["survey_comment"]);
TestReferralSurvey pers = new TestReferralSurvey(p);
pers.additional = TestAdditional.BuildAdditionalFromDataBaseData(idReferral);
if (personFromDataBase["id_survey_organ"] != DBNull.Value)
pers.surveyOrgan = TestCoding.BuildCodingFromDataBaseData(Convert.ToString(personFromDataBase["id_survey_organ"]));
if (personFromDataBase["id_survey_type"] != DBNull.Value)
pers.surveyType = TestCoding.BuildCodingFromDataBaseData(Convert.ToString(personFromDataBase["id_survey_type"]));
return pers;
}
}
}
return null;
}
示例9: getList
public List<Product> getList()
{
using (NpgsqlConnection connection = getConnection())
{
using (NpgsqlCommand cmd = new NpgsqlCommand(SELECT_CMD, connection))
{
connection.Open();
List<Product> result = new List<Product>();
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Product temp = new Product();
temp.id = reader.GetGuid(0);
temp.description = reader.GetString(1);
temp.productGroupID = reader.GetGuid(2);
temp.Unit = Units.FromName(reader.GetString(3));
if (!reader.IsDBNull(4))
{
temp.weight = (Decimal)reader.GetFloat(4);
}
temp.money = reader.GetDecimal(5);
temp.quantity = reader.GetInt32(6);
result.Add(temp);
}
}
return result;
}
}
}
示例10: AccessMaster
public static void AccessMaster(string Action, string TableName, Hashtable hash)
{
using(NpgsqlConnection con = new NpgsqlConnection(CONNECTION_STRING))
{
string query = string.Format(@"SELECT * FROM ""{0}""", TableName);
using(NpgsqlCommand cmd = new NpgsqlCommand(@query, con))
{
NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
adapter.SelectCommand = cmd;
NpgsqlCommand actionCommand = null;
if(Action == "Entry"){
actionCommand = (new NpgsqlCommandBuilder(adapter)).GetInsertCommand();
} else if(Action == "Modify"){
actionCommand = (new NpgsqlCommandBuilder(adapter)).GetUpdateCommand();
} else if(Action == "Remove"){
actionCommand = (new NpgsqlCommandBuilder(adapter)).GetDeleteCommand();
}
try {
foreach(NpgsqlParameter param in actionCommand.Parameters){
if(hash[param.SourceColumn] != null)
param.Value = hash[param.SourceColumn];
}
actionCommand.ExecuteNonQuery();
} catch (Exception ex) {
MessageBox.Show(string.Format("{0}", ex.Message));
MessageBox.Show(string.Format("{0}", ex.StackTrace.ToString()));
}
}
}
}
示例11: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
string check;
string id_wyp = TextBox1.Text;
string nazwa = TextBox2.Text;
string opis = TextBox3.Text;
NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgres;Password=projekt;Database=projekt;");
conn.Open();
NpgsqlCommand check1 = new NpgsqlCommand("select id_wyp from wyposazenie where id_wyp = '" + id_wyp + "'", conn);
check = (String)check1.ExecuteScalar();
if (check != id_wyp)
{
NpgsqlCommand add = new NpgsqlCommand("insert into wyposazenie values ('" + id_wyp + "', '" + nazwa + "', '" + opis + "')", conn);
add.ExecuteScalar();
conn.Close();
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
Label2.Text = "Dodano wyposażenie!";
Label3.Text = "";
}
else if (check == id_wyp)
{
Label2.Text = "";
Label3.Text = "Wyposażenie już istnieje!";
}
}
示例12: BuildPersonFromDataBaseData
public static TestPerson BuildPersonFromDataBaseData(string idPerson, string MIS)
{
using (NpgsqlConnection connection = Global.GetSqlConnection())
{
string findPatient = "SELECT * FROM public.person WHERE id_person = '" + idPerson + "'";
NpgsqlCommand person = new NpgsqlCommand(findPatient, connection);
using (NpgsqlDataReader personFromDataBase = person.ExecuteReader())
{
Person p = new Person();
while (personFromDataBase.Read())
{
//что делать с DateSpecified и Мисами?
if (personFromDataBase["birthday"]!= DBNull.Value)
p.BirthDate = Convert.ToDateTime(personFromDataBase["birthday"]);
if (MIS == "")
p.IdPatientMis = null;
if ((personFromDataBase["family_name"] != DBNull.Value) || (personFromDataBase["given_name"] != DBNull.Value) || (personFromDataBase["middle_name"] != DBNull.Value))
{
p.HumanName = new HumanName();
if (personFromDataBase["family_name"] != DBNull.Value)
p.HumanName.FamilyName = Convert.ToString(personFromDataBase["family_name"]);
if (personFromDataBase["given_name"] != DBNull.Value)
p.HumanName.GivenName = Convert.ToString(personFromDataBase["given_name"]);
if (personFromDataBase["middle_name"] != DBNull.Value)
p.HumanName.MiddleName = Convert.ToString(personFromDataBase["middle_name"]);
}
TestPerson pers = new TestPerson(p);
if (personFromDataBase["id_sex"] != DBNull.Value)
pers.sex = TestCoding.BuildCodingFromDataBaseData(Convert.ToString(personFromDataBase["id_sex"]));
return pers;
}
}
}
return null;
}
示例13: ParametersGetName
public void ParametersGetName()
{
var command = new NpgsqlCommand();
// Add parameters.
command.Parameters.Add(new NpgsqlParameter(":Parameter1", DbType.Boolean));
command.Parameters.Add(new NpgsqlParameter(":Parameter2", DbType.Int32));
command.Parameters.Add(new NpgsqlParameter(":Parameter3", DbType.DateTime));
command.Parameters.Add(new NpgsqlParameter("Parameter4", DbType.DateTime));
var idbPrmtr = command.Parameters["Parameter1"];
Assert.IsNotNull(idbPrmtr);
command.Parameters[0].Value = 1;
// Get by indexers.
Assert.AreEqual(":Parameter1", command.Parameters[":Parameter1"].ParameterName);
Assert.AreEqual(":Parameter2", command.Parameters[":Parameter2"].ParameterName);
Assert.AreEqual(":Parameter3", command.Parameters[":Parameter3"].ParameterName);
//Assert.AreEqual(":Parameter4", command.Parameters["Parameter4"].ParameterName); //Should this work?
Assert.AreEqual(":Parameter1", command.Parameters[0].ParameterName);
Assert.AreEqual(":Parameter2", command.Parameters[1].ParameterName);
Assert.AreEqual(":Parameter3", command.Parameters[2].ParameterName);
Assert.AreEqual("Parameter4", command.Parameters[3].ParameterName);
}
示例14: GetRoutines
public IEnumerable<Routine> GetRoutines()
{
var list = new List<Routine>();
using (var sqlConnection = new NpgsqlConnection(connectionString))
{
using (var cmd = new NpgsqlCommand(@"
SELECT routine_name
FROM INFORMATION_SCHEMA.routines
WHERE
routine_schema <> 'pg_catalog'
and routine_schema <>'information_schema'
", sqlConnection))
{
sqlConnection.Open();
cmd.CommandType = CommandType.Text;
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
list.Add(new Routine(reader.GetString(0)));
}
}
}
}
return list;
}
示例15: ExecuteNonQuery
public static bool ExecuteNonQuery(string catalog, NpgsqlCommand command)
{
try
{
if (command != null)
{
if (ValidateCommand(command))
{
using (NpgsqlConnection connection = new NpgsqlConnection(DbConnection.GetConnectionString(catalog)))
{
command.Connection = connection;
connection.Open();
command.ExecuteNonQuery();
return true;
}
}
}
return false;
}
catch (NpgsqlException ex)
{
if (ex.Code.StartsWith("P"))
{
string errorMessage = GetDBErrorResource(ex);
throw new MixERPException(errorMessage, ex);
}
throw;
}
}