<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.mkcs.at/wikien/index.php?action=history&amp;feed=atom&amp;title=CSharp_PostgreSQL</id>
	<title>CSharp PostgreSQL - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.mkcs.at/wikien/index.php?action=history&amp;feed=atom&amp;title=CSharp_PostgreSQL"/>
	<link rel="alternate" type="text/html" href="https://wiki.mkcs.at/wikien/index.php?title=CSharp_PostgreSQL&amp;action=history"/>
	<updated>2026-05-03T19:41:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://wiki.mkcs.at/wikien/index.php?title=CSharp_PostgreSQL&amp;diff=360&amp;oldid=prev</id>
		<title>MkWikiEnSysOp: Added category PostgreSQL</title>
		<link rel="alternate" type="text/html" href="https://wiki.mkcs.at/wikien/index.php?title=CSharp_PostgreSQL&amp;diff=360&amp;oldid=prev"/>
		<updated>2022-06-05T19:02:42Z</updated>

		<summary type="html">&lt;p&gt;Added category PostgreSQL&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:02, 5 June 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l64&quot;&gt;Line 64:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 64:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Linux]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Linux]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Programming]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Programming]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:PostgreSQL]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MkWikiEnSysOp</name></author>
	</entry>
	<entry>
		<id>https://wiki.mkcs.at/wikien/index.php?title=CSharp_PostgreSQL&amp;diff=268&amp;oldid=prev</id>
		<title>MkWikiEnSysOp: /* Insert data to table with variables */</title>
		<link rel="alternate" type="text/html" href="https://wiki.mkcs.at/wikien/index.php?title=CSharp_PostgreSQL&amp;diff=268&amp;oldid=prev"/>
		<updated>2020-02-06T06:59:34Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Insert data to table with variables&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 06:59, 6 February 2020&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l24&quot;&gt;Line 24:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 24:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Insert data to table with variables ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Insert data to table with variables ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It is best practice to use variables (also called bind variables). &amp;#039;&amp;#039;&amp;#039;Do not consider&amp;#039;&amp;#039;&amp;#039; concatenating a string and build a query string yourself! This makes your application vulnerable to security problems, namely SQL injection. Ask your favorite search engine about it, &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;that &lt;/del&gt;are millions of articles addressing that.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It is best practice to use variables (also called bind variables). &amp;#039;&amp;#039;&amp;#039;Do not consider&amp;#039;&amp;#039;&amp;#039; concatenating a string and build a query string yourself! This makes your application vulnerable to security problems, namely SQL injection. Ask your favorite search engine about it, &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;there &lt;/ins&gt;are millions of articles addressing that.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  int ra = -1;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  int ra = -1;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MkWikiEnSysOp</name></author>
	</entry>
	<entry>
		<id>https://wiki.mkcs.at/wikien/index.php?title=CSharp_PostgreSQL&amp;diff=65&amp;oldid=prev</id>
		<title>MkWikiEnSysOp: 3 revisions imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.mkcs.at/wikien/index.php?title=CSharp_PostgreSQL&amp;diff=65&amp;oldid=prev"/>
		<updated>2018-06-28T17:19:36Z</updated>

		<summary type="html">&lt;p&gt;3 revisions imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article is about developing database applications in C# using PostgreSQL. I developed such an application to transfer the consumption values of my smart meter from a comma seperated values (CSV) file to a PostgreSQL database.&lt;br /&gt;
&lt;br /&gt;
== Packages ==&lt;br /&gt;
&lt;br /&gt;
* pgadmin3 - this is for convenient working with PostgreSQL&lt;br /&gt;
* libmono-npgsql4.0-cil (Mono Npgsql library (for CLI 4.0) - installs the bindings needed for developing a C# application that talks to PostgreSQL)&lt;br /&gt;
&lt;br /&gt;
== MonoDevelop ==&lt;br /&gt;
&lt;br /&gt;
In a C# solution, &amp;quot;Npgsql.dll&amp;quot; - usually found in /usr/lib/mono/4.0/Npgsql.dll - must be added.&lt;br /&gt;
&lt;br /&gt;
== C# examples ==&lt;br /&gt;
&lt;br /&gt;
=== Opening connection ===&lt;br /&gt;
&lt;br /&gt;
 var connString = @&amp;quot;server=localhost;userid=smartmeter;password=SECRET;database=smartmeter;&amp;quot;;&lt;br /&gt;
 using (var conn = new NpgsqlConnection(connString))&lt;br /&gt;
 {&lt;br /&gt;
   conn.Open();&lt;br /&gt;
   // Server version can be found in conn.ServerVersion&lt;br /&gt;
   // Do something with connection&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== Insert data to table with variables ===&lt;br /&gt;
&lt;br /&gt;
It is best practice to use variables (also called bind variables). &amp;#039;&amp;#039;&amp;#039;Do not consider&amp;#039;&amp;#039;&amp;#039; concatenating a string and build a query string yourself! This makes your application vulnerable to security problems, namely SQL injection. Ask your favorite search engine about it, that are millions of articles addressing that.&lt;br /&gt;
&lt;br /&gt;
 int ra = -1;&lt;br /&gt;
 using (var insertCommand = conn.CreateCommand()) {&lt;br /&gt;
   insertCommand.Connection = conn;&lt;br /&gt;
   insertCommand.CommandText = &amp;quot;insert into meteringvalues &amp;quot; + &amp;quot;(devicenr, tariff, source, sourcetype, \&amp;quot;timestamp\&amp;quot;, value) values &amp;quot; + &amp;quot;(:devicenr, :tariff, :source, :sourcetype, :timestamp, :value)&amp;quot;;&lt;br /&gt;
   insertCommand.Parameters.Add(&amp;quot;devicenr&amp;quot;, NpgsqlTypes.NpgsqlDbType.Varchar, 20).Value = DeviceNr;&lt;br /&gt;
   insertCommand.Parameters.Add(&amp;quot;tariff&amp;quot;, NpgsqlTypes.NpgsqlDbType.Bigint).Value = Tariff;&lt;br /&gt;
   insertCommand.Parameters.Add(&amp;quot;source&amp;quot;, NpgsqlTypes.NpgsqlDbType.Bigint).Value = Source;&lt;br /&gt;
   insertCommand.Parameters.Add(&amp;quot;sourcetype&amp;quot;, NpgsqlTypes.NpgsqlDbType.Bigint).Value = SourceType;&lt;br /&gt;
   insertCommand.Parameters.Add(&amp;quot;timestamp&amp;quot;, NpgsqlTypes.NpgsqlDbType.Timestamp).Value = Timestamp;&lt;br /&gt;
   insertCommand.Parameters.Add(&amp;quot;value&amp;quot;, NpgsqlTypes.NpgsqlDbType.Double).Value = value;&lt;br /&gt;
   insertCommand.Prepare ();&lt;br /&gt;
   int ra = insertCommand.ExecuteNonQuery ();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
However, there is one caveat of that solution: If you change your database schema, you also have to change your application&amp;#039;s code. It is better to write a stored procedure that finally inserts the data to the destination table. This also enables you to check values, transform them, dispatch them to different tables and so on &amp;#039;&amp;#039;&amp;#039;in the database&amp;#039;&amp;#039;&amp;#039; (hence don&amp;#039;t having the need to change the application which requires deploying it again).&lt;br /&gt;
&lt;br /&gt;
To complete that example, here is the definition of the table:&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE meteringvalues&lt;br /&gt;
 (&lt;br /&gt;
   devicenr character(20),&lt;br /&gt;
   tariff bigint,&lt;br /&gt;
   source bigint,&lt;br /&gt;
   sourcetype bigint,&lt;br /&gt;
   &amp;quot;timestamp&amp;quot; timestamp without time zone,&lt;br /&gt;
   value double precision&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
== Help ==&lt;br /&gt;
&lt;br /&gt;
These web pages were helpful:&lt;br /&gt;
&lt;br /&gt;
* [https://help.ubuntu.com/community/PostgreSQL PostgreSQL in Ubuntu Help]&lt;br /&gt;
* [http://www.sqlines.com/postgresql/npgsql_dotnet PostgreSQL and C#]&lt;br /&gt;
* [http://www.npgsql.org/doc/manual-2.2.html npgsql User Manual]&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>MkWikiEnSysOp</name></author>
	</entry>
</feed>