Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

A CRUD Form using SharpDevelop and PostgreSQL

, 21 Oct 2009
This article is a tutorial on how to create a CRUD (Create, Retrieve, Update and Delete) Form using SharpDevelop and PostgreSQL, implementing a BindingNavigator to explore the table used in the application.
CRUD_Music.zip
CRUD_Music
de
Npgsql.resources.dll
es
Npgsql.resources.dll
fi
Npgsql.resources.dll
fr
Npgsql.resources.dll
ja
Npgsql.resources.dll
Mono.Security.dll
Music.ex_
Npgsql.dll
zh-CN
Npgsql.resources.dll
CRUD_MusicSRC.zip
CRUD_MusicSRC
Music
Properties
/*
 * Created by SharpDevelop.
 * User: wancho
 * Date: 20/10/2009
 * Time: 14:37
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Npgsql;
namespace Music
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		void MainFormLoad(object sender, EventArgs e)
		{
			// We fill our DataSet and we set the table in the Dataset as "artists"
			adapter.Fill(mainDS,"artists");
			// We must set the DataMember property in the BindingSource
			// it cannot be set at the designer since our DataSet isn't populated
		   bsource.DataMember="artists";
		   // We add the DataBinding to the TextBox linked to the "Text" property
		   // and linked to the BindingSource
		   t_artistID.DataBindings.Add("Text",bsource,"artistid");
		   t_name.DataBindings.Add("Text",bsource,"name");
          // Now we must set the Relation between the parameters and the fields 
          // in the Database
          cmdInsert.Parameters.Add(new NpgsqlParameter("p_artistID",NpgsqlTypes.NpgsqlDbType.Integer,0,"artistid"));
          cmdInsert.Parameters.Add(new NpgsqlParameter("p_name",NpgsqlTypes.NpgsqlDbType.Varchar,0,"name"));
          cmdDelete.Parameters.Add(new NpgsqlParameter("p_artistID",NpgsqlTypes.NpgsqlDbType.Integer,0,"artistid"));
          cmdUpdate.Parameters.Add(new NpgsqlParameter("p_artistID",NpgsqlTypes.NpgsqlDbType.Integer,0,"artistid"));
          cmdUpdate.Parameters.Add(new NpgsqlParameter("p_name",NpgsqlTypes.NpgsqlDbType.Varchar,0,"name"));
          
		}
		
		void ToolStripButton1Click(object sender, EventArgs e)
		{
			// We call this method to officialy end the editing of the Bindingsource
			bsource.EndEdit();
			// Now we will try to update our table
			try {
				adapter.Update(mainDS.Tables["artists"]);
			}
			// We must catch the Exception, because the user may cause a SQL exception 
			catch (Exception e_exception)
			{
				MessageBox.Show("Error.... "+e_exception.Message,"Error tryng to commit");
			}
		}
	}
}

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 Code Project Open License (CPOL)

Share

About the Author

Juan Fajardo
Software Developer TuXSTONe Technologies
Colombia Colombia
Colombian, TuXSTONe Technologies developer,
Software Developer since 1996,
Computers Engineer and Network Software Developing Specialist since 2003.
 
Experience in developing software using PHP,C, C#, Java, Perl.

| Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 21 Oct 2009
Article Copyright 2009 by Juan Fajardo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid