Exemple #1
0
 public static List<string> GetColumnString(string s)
 {
     DBConnect db = new DBConnect(connString);
     //MySqlConnection conn = new MySqlConnection(connString);
     MySqlCommand command = db.conn.CreateCommand();
     command.CommandText = "SELECT COLUMN_NAME FROM information_schema.COLUMNS C WHERE table_name = '" + s + "'";
     List<string> list = new List<string>();
     try
     {
         db.conn.Open();
         using (var reader = command.ExecuteReader(CommandBehavior.KeyInfo))
         {
             while (reader.Read())
             {
                 list.Add(reader.GetString(0));
             }
             //var table = reader.GetSchemaTable();
             //foreach (DataColumn column in table.Columns)
             //{
             //    Console.WriteLine(column.ColumnName.ToString());
             //    list.Add(column.ColumnName);
             //}
             foreach (var element in list)
             {
                 Console.WriteLine(element);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally { db.conn.Close(); }
     return list;
 }
Exemple #2
0
        public List<string> GetTables()
        {
            List<string> TableNames = new List<string>();
            try
            {
                //MySqlConnection connection = new MySqlConnection(connString)
                db = new DBConnect(connString);
                db.conn.Open();
                //using (db.conn.Open())
                //{
                    //connection.Open();
                    DataTable schema = db.conn.GetSchema("Tables");

                    foreach (DataRow row in schema.Rows)
                    {
                        TableNames.Add(row[2].ToString());
                    }

                ////}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                db.conn.Close();
            }
            //foreach (var element in TableNames)
            //{
            //    Console.WriteLine(element);
            //}

            return TableNames;
        }
Exemple #3
0
        public static List<string> GetTables()
        {
            DBConnect db = new DBConnect(connString);
            List<string> TableNames = new List<string>();
            try
            {
                //using (MySqlConnection connection = new MySqlConnection(connString))
                //{
                    //connection.Open();

                db.conn.Open();
                    DataTable schema = db.conn.GetSchema("Tables");

                    foreach (DataRow row in schema.Rows)
                    {
                        TableNames.Add(row[2].ToString());
                    }

                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                db.conn.Close();
            }
            return TableNames;
        }
Exemple #4
0
        public void updateChart()
        {
            tabelList = GetTables();

            foreach (var series in chart1.Series)
            {
                series.Points.Clear();
            }

            db = new DBConnect(connString);
            try
            {
                db.conn.Open();
                for (int i = 0; i < tabelList.Count; i++)
                {
                    string comandString = "SELECT COUNT(*) FROM ";
                    comandString += tabelList[i];
                    int count = 0;

                    using (MySqlCommand cmd1 = new MySqlCommand(comandString, db.conn))
                    {
                        //db.conn.Open();
                        count = int.Parse(cmd1.ExecuteScalar().ToString());
                    }
                    this.chart1.Series["Number of records"].Points.AddXY(tabelList[i], count);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                db.conn.Close();
            }
        }
Exemple #5
0
        private void button3_Click(object sender, EventArgs e)
        {
            DBConnect db = new DBConnect(connString);
            try
            {
                Console.WriteLine(creareStringComanda());
                comanda = creareStringComanda();

                MySqlCommand com=new MySqlCommand(comanda,db.conn);
                db.conn.Open();
                com.ExecuteNonQuery();
                label2.Text = "Done";
            }catch(Exception ex)
            {
                label2.Text = "Error";
                MessageBox.Show(ex.Message);
            }finally{
                db.conn.Close();
            }
        }
Exemple #6
0
 private void button1_Click(object sender, EventArgs e)
 {
     DBConnect db = new DBConnect(connString);
     MySqlCommand com = new MySqlCommand(getCommandString(), db.conn);
     Console.WriteLine(getCommandString());
     try
     {
         db.conn.Open();
         com.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         db.conn.Close();
         this.Close();
     }
 }