コード例 #1
0
ファイル: DbTools.cs プロジェクト: ChristianWoeber/DBTools
 public static IDataReader CreateQuery(SQLCmd sqlCmd, DbConnection con, MySQLCommandBuilder builder)
 {
     try
     {
         _dbCon             = con;
         _dbCmd             = con.CreateCommand();
         _dbCmd.CommandText = builder.CmdBuilder.ToString();
         return(_dbCmd.ExecuteReader());
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     return(null);
 }
コード例 #2
0
ファイル: DbTools.cs プロジェクト: ChristianWoeber/DBTools
        internal static void Exec(DbConnection con, MySQLCommandBuilder builder)
        {
            try
            {
                using (_dbCon = con)
                    using (_dbCmd = con.CreateCommand())
                    {
                        if (builder.SQLCmdType == SQLCommandTypes.Insert || builder.SQLCmdType == SQLCommandTypes.Delete ||
                            builder.SQLCmdType == SQLCommandTypes.Update)
                        {
                            _dbCmd.CommandText = builder.CmdBuilder.ToString();

                            //cmd.CommandText = "INSERT INTO Authors(Name) VALUES(@Name)";
                            //  cmd.Prepare();
                            //cmd.Parameters.AddWithValue("@Name", "Trygve Gulbranssen");

                            _dbCmd.ExecuteNonQuery();
                        }

                        Console.WriteLine($"folgendes Command erfolgreich ausgeführt: {_dbCmd.CommandText}");
                        Console.ReadLine();
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
            //finally
            //{
            //    if (_dbCmd != null)
            //        _dbCmd.Dispose();
            //    if (_dbCon != null)
            //        _dbCon.Dispose();
            //}
        }
コード例 #3
0
 public SQLCmd(DbConnection connection, SQLCommandTypes cmdtype)
 {
     Connection = connection;
     cmdTpye    = cmdtype;
     _builder   = new MySQLCommandBuilder(cmdTpye, _db, _table);
 }