Beispiel #1
0
        private void btnDbPath_Click(object sender, EventArgs e)
        {
            FileDialog fd = new OpenFileDialog();

            fd.Filter = "Access Database file |*.accdb";
            if (fd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                tbAccessDBPath.Text         = fd.FileName;
                Passvalues.connectionString = string.Format("Provider=Microsoft.ACE.Oledb.12.0;Data Source=" + tbAccessDBPath.Text.Trim() + ";");
                connection = DB_Connection.GetDBConnection();
            }
        }
Beispiel #2
0
        private bool ifExistsInDB(string ID)
        {
            try
            {
                if (connection == null || connection.ConnectionString == null || connection.ConnectionString.Trim() == "")
                {
                    connection = DB_Connection.GetDBConnection();
                }
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }
                setLastEditDate();

                string query = "SELECT * FROM [" + tbTableName.Text.Trim() + "]  WHERE  [ID] =" + ID + "";
                adapter = new OleDbDataAdapter(query, connection);


                DataTable datarow = new DataTable();
                //adapter.Fill(Convert.ToInt32(startIndex), 100, dt);
                adapter.Fill(datarow);
                if (datarow.Rows.Count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (OleDbException e)
            {
                MessageBox.Show(e.Message);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (connection.State != ConnectionState.Closed)
                {
                    if (adapter != null)
                    {
                        adapter.Dispose();
                    }
                    connection.Close();
                    connection.Dispose();
                }
            }
            return(false);
        }
Beispiel #3
0
        private void updateRecords()
        {
            try
            {
                if (connection == null || connection.ConnectionString == null || connection.ConnectionString.Trim() == "")
                {
                    connection = DB_Connection.GetDBConnection();
                }
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }
                setLastEditDate();


                string query = "SELECT * FROM [" + tbTableName.Text.Trim() + "]  WHERE  [Edit Date] > #" + Passvalues.lastUpdateDate + "#";
                adapter = new OleDbDataAdapter(query, connection);

                dt.Dispose();
                dt = new DataTable();
                //adapter.Fill(Convert.ToInt32(startIndex), 100, dt);
                adapter.Fill(dt);
                progressBar1.Maximum = dt.Rows.Count;
                adapter.Dispose();
                contactList = new List <OutLook.ContactItem>();
                MethodInvoker m = new MethodInvoker(() => progressBar1.Maximum = Convert.ToInt16(dt.Rows.Count));
                progressBar1.Invoke(m);
            }
            catch (OleDbException e)
            {
                MessageBox.Show(e.Message);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (connection.State != ConnectionState.Closed)
                {
                    adapter.Dispose();
                    connection.Close();
                    connection.Dispose();
                }
            }
        }
Beispiel #4
0
        private void getContacts()
        {
            try
            {
                if (count == 0)
                {
                    setCount();
                }
                if (connection == null || connection.ConnectionString == null || connection.ConnectionString.Trim() == "")
                {
                    connection = DB_Connection.GetDBConnection();
                }
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }

                MethodInvoker m = new MethodInvoker(() => progressBar1.Maximum = Convert.ToInt16(count));
                progressBar1.Invoke(m);
                string query = "SELECT * FROM [" + tbTableName.Text.Trim() + "] ORDER BY ID";
                adapter = new OleDbDataAdapter(query, connection);
                dt.Dispose();
                dt = new DataTable();
                adapter.Fill(Convert.ToInt32(startIndex), 100, dt);
                adapter.Dispose();
                contactList = new List <OutLook.ContactItem>();
            }
            catch (OleDbException e)
            {
                MessageBox.Show(e.Message);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (connection.State != ConnectionState.Closed)
                {
                    adapter.Dispose();
                    connection.Close();
                    connection.Dispose();
                }
            }
        }
Beispiel #5
0
 private void setCount()
 {
     try
     {
         if (connection == null || connection.ConnectionString == null || connection.ConnectionString.Trim() == "")
         {
             connection = DB_Connection.GetDBConnection();
         }
         if (connection.State == ConnectionState.Closed)
         {
             connection.Open();
         }
         string query = "SELECT count(*) FROM [" + tbTableName.Text.Trim() + "]";
         adapter = new OleDbDataAdapter(query, connection);
         dt.Dispose();
         dt = new DataTable();
         adapter.Fill(dt);
         count = Convert.ToInt64(dt.Rows[0][0].ToString());
     }
     catch (OleDbException e)
     {
         MessageBox.Show(e.Message);
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         if (connection.State != ConnectionState.Closed)
         {
             connection.Close();
             connection.Dispose();
         }
     }
 }