Click here to Skip to main content
15,895,793 members
Articles / Programming Languages / SQL

Using PostgreSQL in your C# (.NET) application (An introduction)

Rate me:
Please Sign up or sign in to vote.
4.92/5 (80 votes)
15 Nov 2008BSD4 min read 775.1K   15.9K   112  
In this article, I would like to show you step by step how to use this fantastic database in your C# application.
namespace PostgreSQLTEst
{
	partial class Form1
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.dataGridView1 = new System.Windows.Forms.DataGridView();
			this.tbHost = new MultiCtrls.LabeledTextBox();
			this.tbPort = new MultiCtrls.LabeledTextBox();
			this.tbUser = new MultiCtrls.LabeledTextBox();
			this.tbPass = new MultiCtrls.LabeledTextBox();
			this.tbDataBaseName = new MultiCtrls.LabeledTextBox();
			this.llOpenConnAndSelect = new System.Windows.Forms.LinkLabel();
			((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
			this.SuspendLayout();
			// 
			// dataGridView1
			// 
			this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.dataGridView1.Location = new System.Drawing.Point(12, 96);
			this.dataGridView1.Name = "dataGridView1";
			this.dataGridView1.Size = new System.Drawing.Size(629, 347);
			this.dataGridView1.TabIndex = 0;
			// 
			// tbHost
			// 
			this.tbHost.LabelText = "Host adress";
			this.tbHost.Location = new System.Drawing.Point(98, 12);
			this.tbHost.Name = "tbHost";
			this.tbHost.offset = 5;
			this.tbHost.Size = new System.Drawing.Size(100, 20);
			this.tbHost.TabIndex = 1;
			// 
			// tbPort
			// 
			this.tbPort.LabelText = "Port";
			this.tbPort.Location = new System.Drawing.Point(98, 38);
			this.tbPort.Name = "tbPort";
			this.tbPort.offset = 5;
			this.tbPort.Size = new System.Drawing.Size(100, 20);
			this.tbPort.TabIndex = 4;
			// 
			// tbUser
			// 
			this.tbUser.LabelText = "User";
			this.tbUser.Location = new System.Drawing.Point(301, 12);
			this.tbUser.Name = "tbUser";
			this.tbUser.offset = 5;
			this.tbUser.Size = new System.Drawing.Size(100, 20);
			this.tbUser.TabIndex = 6;
			// 
			// tbPass
			// 
			this.tbPass.LabelText = "Password";
			this.tbPass.Location = new System.Drawing.Point(541, 12);
			this.tbPass.Name = "tbPass";
			this.tbPass.offset = 5;
			this.tbPass.Size = new System.Drawing.Size(100, 20);
			this.tbPass.TabIndex = 7;
			// 
			// tbDataBaseName
			// 
			this.tbDataBaseName.LabelText = "Database name";
			this.tbDataBaseName.Location = new System.Drawing.Point(301, 38);
			this.tbDataBaseName.Name = "tbDataBaseName";
			this.tbDataBaseName.offset = 5;
			this.tbDataBaseName.Size = new System.Drawing.Size(100, 20);
			this.tbDataBaseName.TabIndex = 10;
			// 
			// llOpenConnAndSelect
			// 
			this.llOpenConnAndSelect.AutoSize = true;
			this.llOpenConnAndSelect.Location = new System.Drawing.Point(441, 45);
			this.llOpenConnAndSelect.Name = "llOpenConnAndSelect";
			this.llOpenConnAndSelect.Size = new System.Drawing.Size(200, 13);
			this.llOpenConnAndSelect.TabIndex = 11;
			this.llOpenConnAndSelect.TabStop = true;
			this.llOpenConnAndSelect.Text = "Open connection and bake simple select";
			this.llOpenConnAndSelect.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llOpenConnAndSelect_LinkClicked);
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(662, 455);
			this.Controls.Add(this.llOpenConnAndSelect);
			this.Controls.Add(this.tbDataBaseName);
			this.Controls.Add(this.tbPass);
			this.Controls.Add(this.tbUser);
			this.Controls.Add(this.tbPort);
			this.Controls.Add(this.tbHost);
			this.Controls.Add(this.dataGridView1);
			this.Name = "Form1";
			this.Text = "Form1";
			((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
			this.ResumeLayout(false);
			this.PerformLayout();

		}

		#endregion

		private System.Windows.Forms.DataGridView dataGridView1;
		private MultiCtrls.LabeledTextBox tbHost;
		private MultiCtrls.LabeledTextBox tbPort;
		private MultiCtrls.LabeledTextBox tbUser;
		private MultiCtrls.LabeledTextBox tbPass;
		private MultiCtrls.LabeledTextBox tbDataBaseName;
		private System.Windows.Forms.LinkLabel llOpenConnAndSelect;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Software Developer Agilion Consulting
Poland Poland
I specialize at C#, developing Enterprise solutions. I have some knowledge of ASP.NET MVC - looking forward to use it together with Typescript.

Comments and Discussions