Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / SQL

Beginner’s Tutorial on Using the Firebird ADO.NET Client 2.5

Rate me:
Please Sign up or sign in to vote.
4.82/5 (30 votes)
25 Mar 2009CPOL7 min read 185.5K   5.2K   44  
In this article, I will show you how to interface your simple C# applications to the FirebirdSQL Server using the Firebird ADO.NET Client 2.5.
/*
 * Created by SharpDevelop.
 * User: B.H.M
 * Date: 2/24/2009
 * Time: 4:32 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using FirebirdSql.Data.FirebirdClient;

namespace UsingFirebird
{
	/// <summary>
	/// Description of FormDelete.
	/// </summary>
	public partial class FormDelete : Form
	{
		public FormDelete()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		
		/* i have developed a habit of putting connection strings up here to widen there scope
		 this way, you dont have to write it everytime in an event handler!*/
		string ConnectionString = 
	"User ID=sysdba;Password=12345;Database=localhost:C:\\USINGFIREBIRD.FDB;DataSource=localhost;Charset=NONE;"; 
		
		
		void FormDeleteLoad(object sender, EventArgs e)
		{
			FbConnection deleteConnection = new FbConnection(ConnectionString);
			try
			{
            deleteConnection.Open();
            
            // declare command
            FbCommand readCommand = new FbCommand("Select * From Details",deleteConnection);
            FbDataReader myreader=  readCommand.ExecuteReader();
            while(myreader.Read())
            {
            	// load the combobox with the names of the people inside. myreader[0] reads from the 1st Column
            	DeleteComboBox.Items.Add(myreader[0]);
            }
            myreader.Close(); // we are done with the reader
			}
			catch(Exception x)
			{
				MessageBox.Show(x.Message);
			}
			finally
			{
				
				deleteConnection.Close(); 
			}
            
        }
            
			
		
		void DeleteButtonClick(object sender, EventArgs e)
		{
			try
			{
	
			FbConnection deleteConnection = new FbConnection(ConnectionString);
            deleteConnection.Open();
            
            FbTransaction deleteTransaction = deleteConnection.BeginTransaction();
            FbCommand deleteCommand = 
            	new FbCommand("Delete From Details where Name = "+"'"+DeleteComboBox.SelectedItem.ToString()+"'",deleteConnection,deleteTransaction);
		
            deleteCommand.ExecuteNonQuery();
            deleteTransaction.Commit();
            MessageBox.Show(" Item Deleted");
            deleteConnection.Close();
			}
			catch(Exception x)
			{
				MessageBox.Show(x.Message);
			}
			}
			
            
		}
	}
		
		

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)


Written By
Engineer
United Kingdom United Kingdom
I have deserted general software development and chosen to enter microprocessors and push around 1s and 0s

Comments and Discussions