Esempio n. 1
0
        public void RunQuery(int queryId, string tables, string columns, string condition, string values)
        {
            qDirector = new QueryDirector(qFactory.CreateQueryBuilder(queryId));

            qDirector.MakeQuery(tables, columns, condition, values);

            query = qDirector.GetQuery;

            try
            {
                using (dbConnect)
                    using (command = new MySqlCommand(query, dbConnect))
                    {
                        dbConnect.Open();
                        command.ExecuteNonQuery();
                        dbConnect.Close();
                    }
            }
            catch (Exception e)
            {
                UIComponents.UIError error = new UIComponents.UIError("Error, could not connect to server", "OK");
                error.ShowDialog();
                MessageBox.Show(query);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Runs the requested query
        /// </summary>
        /// <param name="id"></param>
        /// <param name="tables"></param>
        /// <param name="columns"></param>
        /// <param name="condition"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public DataTable RunSelectQuery(string tables, string columns, string condition)
        {
            DataTable dt = new DataTable();

            qDirector = new QueryDirector(new SelectQueryBuilder());
            qDirector.MakeQuery(tables, columns, condition, "");

            query = qDirector.GetQuery;

            try
            {
                using (dbConnect)
                    using (command = new MySqlCommand(query, dbConnect))
                        using (adp = new MySqlDataAdapter(command))
                        {
                            dbConnect.Open();
                            adp.Fill(dt);
                            dbConnect.Close();
                        }

                return(dt);
            }
            catch (Exception e)
            {
                UIComponents.UIError error = new UIComponents.UIError("Error, could not connect to server", "OK");
                error.ShowDialog();
                MessageBox.Show(query);
            }

            return(null);
        }