Click here to Skip to main content
15,885,216 members
Articles / Desktop Programming / Win32

Address Book and Events Reminder

Rate me:
Please Sign up or sign in to vote.
4.74/5 (37 votes)
13 Feb 2009CPOL16 min read 105.2K   10.7K   106  
Allows to maintain and backup your contacts and also maintains a reminder. You can store data in any of the three different databases like Microsoft SQL Server, MySql, Microsoft Access
using System;
using System.Windows.Forms;

namespace AddressBook
{
    public partial class frmAccessSettings : Form
    {
        string Password;

        public frmAccessSettings()
        {
            InitializeComponent();
        }
        
        void OpenMdb(object sender, EventArgs e)
        {
            OpenFileDialog OFD = new OpenFileDialog();
            OFD.Filter = "Microsoft Office Access Database (*.mdb)|*.mdb";
            OFD.ShowDialog();
            txtMDBFile.Text = OFD.FileName;
        }

        void TestConnection(object sender, EventArgs e)
        {
            if(TestConnection())
            MessageBox.Show("Test Connection Succeeded!", "Connection Opened");
        }

        bool TestConnection()
        {
            if (txtMDBFile.Text.Length == 0) { MessageBox.Show("Select the Microsoft Access Database to store data and then try again."); return false; }
            System.Data.OleDb.OleDbConnection Connection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ txtMDBFile.Text+";Persist Security Info=True;Jet OLEDB:Database Password=" + Password + ";");
            try
            {
                Connection.Open();
                Connection.Close();
                Connection = null;
                return true;
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Test Connection Failed.Could not connect to specified database.\n\nError Message:\n" + Ex.Message, "Access Denied");
                Connection = null;
                return false;
            }
        }

        void SaveChanges(object sender, EventArgs e)
        {
            if (TestConnection())
            {
                DataConnection.ConnectionType = (int)ConnectionTypes.AccessConnection;
                DataConnection.DataSource = txtMDBFile.Text;
                DataConnection.Password = Password;
                DataConnection.SaveSettings();
                this.Close();
            }
        }

        void Password_Changed(object sender, EventArgs e)
        {
            Password = txtPassword.Text;
        }

        void CancelSettings(object sender, EventArgs e)
        {
            this.Close();
        }

        void LoadDatas(object sender, EventArgs e)
        {
            txtMDBFile.Text = DataConnection.DataSource;
            Password = DataConnection.Password;
        }
    }
}

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
Software Developer
India India


Completed B.Com(CS) at DGVC and GNIIT Software Engineering at NIIT. Resident at Chennai and working as a Software Engineer.



 Language / Technology :

C#, ADO.NET, ASP.NET, MVC, WCF, ASP, PHP, XML, Java, J2EE, HTML, JavaScript, JQuery, AngularJS, VB Script, C++, MS SQL Server, SSRS, MySql, Oracle, Oracle Forms Development, Windows, Linux.



Click here to view other articles.


Mail Me at:  shridhar_tl@ymail.com


Visit my Site:  www.iCodeIt.in


Comments and Discussions