예제 #1
0
파일: Program.cs 프로젝트: Katinder/dotNet
        private static bool CheckItem(ApiOutput item)
        {
            string check_query = $"SELECT COUNT(*) FROM schema1.local_table WHERE `pk`='{item.c1_pk}';";

            if (OpenConnection() == true)
            {
                MySqlCommand cmd = new MySqlCommand(check_query, conn);
                try
                {
                    int queryOp = int.Parse(cmd.ExecuteScalar().ToString());
                    if (queryOp == 0)
                    {
                        Console.WriteLine("Row doesn't exist.");
                        CloseConnection();
                        return(false);
                    }
                    else //already exists
                    {
                        Console.WriteLine("Row exists.");
                        CloseConnection();
                        return(true);
                    }
                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex.Message);
                    return(false);
                }
            }

            else
            {
                return(false);
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: Katinder/dotNet
        private static void UpdateDb(ApiOutput item)
        {
            string update_query = $"UPDATE schema1.local_table SET `name`='{item.c2_name}', `amount`='{item.c3_amount}' WHERE `pk`= '{item.c1_pk}';";

            if (OpenConnection() == true)
            {
                MySqlCommand cmd = new MySqlCommand(update_query, conn);
                try
                {
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("Row Updated.");
                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                CloseConnection();
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: Katinder/dotNet
        private static void DeleteFromDb(ApiOutput item)
        {
            string delete_query = $"DELETE FROM schema1.local_table WHERE `pk`='{item.c1_pk}';";

            if (OpenConnection() == true)
            {
                MySqlCommand cmd = new MySqlCommand(delete_query, conn);
                try
                {
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("Row Deleted.");
                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                CloseConnection();
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: Katinder/dotNet
        private static void InsertToDb(ApiOutput item)
        {
            string insert_query = $"INSERT INTO schema1.local_table (`pk`, `name`, `amount`) VALUES ('{item.c1_pk}','{item.c2_name}','{item.c3_amount}');"; //'2021-01-28 12:59:52'


            if (OpenConnection() == true)
            {
                MySqlCommand cmd = new MySqlCommand(insert_query, conn);
                try
                {
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("New Row Inserted.");
                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                CloseConnection();
            }
        }