|
/*
* 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.
I have deserted general software development and chosen to enter microprocessors and push around 1s and 0s