private static IDbDataParameter ConvertToNativeParameter(DbParameter dbParameter, CommandType cmdType)
        {
            IDbDataParameter clone = new OracleParameter() { IsNullable = dbParameter.IsNullable };

            // Remove leading ':' character for stored procedures.
            if (cmdType == CommandType.StoredProcedure)
            {
                string name = parameterRenderer.RenderParameterName(dbParameter);
                if (name.StartsWith(":", StringComparison.Ordinal))
                    name = name.Substring(1, name.Length - 1);

                clone.ParameterName = name;
            }
            else
            {
                clone.ParameterName = parameterRenderer.RenderParameterName(dbParameter);
            }

            if (dbParameter.PassMode == SpArgumentPassMode.DataTableFilledByAdapter)
                ((OracleParameter)clone).OracleDbType = OracleDbType.RefCursor;
            else
                clone.DbType = dbParameter.DbType;

            clone.Direction = dbParameter.Direction;
            clone.Precision = dbParameter.Precision;
            clone.Scale = dbParameter.Scale;
            clone.Size = dbParameter.Size;
            clone.SourceColumn = dbParameter.SourceColumn;
            clone.SourceVersion = dbParameter.SourceVersion;
            clone.Value = dbParameter.Value;

            return clone;
        }
        public static SqlCommand GenerateCommand(SqlConnection Connection, MethodInfo Method, object[] Values, CommandType SQLCommandType, string SQLCommandText)
        {
            if (Method == null)
            {
                Method = (MethodInfo)new StackTrace().GetFrame(1).GetMethod();
            }

            SqlCommand command = new SqlCommand();
            command.Connection = Connection;
            command.CommandType = SQLCommandType;

            if (SQLCommandText.Length == 0)
            {
                command.CommandText = Method.Name;
            }
            else
            {
                command.CommandText = SQLCommandText;
            }

            if (command.CommandType == CommandType.StoredProcedure)
            {
                GenerateCommandParameters(command, Method, Values);

                command.Parameters.Add(ReturnValueParameterName, SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
            }

            return command;
        }
Example #3
1
        public static DataSet ExecuteDataSet(CommandType cmdType, string strProcedureName, SqlParameter[] objParameters)
        {
            DataSet dset = new DataSet();
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["db1ConnectionString"].ToString());
            con.Open();
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = cmdType;
                cmd.CommandText = strProcedureName;

                AttachParameters(cmd, objParameters);

                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                ad.Fill(dset);

                return dset;

            }
            catch (Exception ex)
            {
                return dset;
            }
            finally
            {
                con.Close();
            }
        }
Example #4
1
        public static void ExecuteNonQuery( CommandType cmdType, string strProcedureName, SqlParameter[] objParameters)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["db1ConnectionString"].ToString());
            con.Open();
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = cmdType;
                cmd.CommandText = strProcedureName;

                AttachParameters(cmd, objParameters);

                cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {

            }
            finally
            {

                con.Close();
            }
        }
Example #5
1
        // This function will be used to execute CUD(CRUD) operation of parameterized commands
        internal static bool ExecuteNonQuery(string CommandName, CommandType cmdType, SqlParameter[] pars)
        {
            int result = 0;

            using (SqlConnection con = new SqlConnection(CONNECTION_STRING))
            {
                using (SqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandType = cmdType;
                    cmd.CommandText = CommandName;
                    cmd.Parameters.AddRange(pars);

                    try
                    {
                        if (con.State != ConnectionState.Open)
                        {
                            con.Open();
                        }

                        result = cmd.ExecuteNonQuery();
                    }
                    catch
                    {
                        throw;
                    }
                }
            }
            return (result > 0);
        }
Example #6
1
        public DataTable ExecuteParamerizedSelectCommand(string CommandName, CommandType cmdType, SqlParameter[] param)
        {
            SqlCommand cmd = null;
            DataTable table = new DataTable();

            cmd = con.CreateCommand();

            cmd.CommandType = cmdType;
            cmd.CommandText = CommandName;
            cmd.Parameters.AddRange(param);

            try
            {
                con.Open();

                SqlDataAdapter da = null;
                using (da = new SqlDataAdapter(cmd))
                {
                    da.Fill(table);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Dispose();
                cmd = null;
                con.Close();
            }

            return table;
        }
Example #7
1
        // This function will be used to execute R(CRUD) operation of parameterized commands
        internal static DataTable ExecuteParamerizedSelectCommand(string CommandName, CommandType cmdType, SqlParameter[] param)
        {
            DataTable table = new DataTable();

            using (SqlConnection con = new SqlConnection(CONNECTION_STRING))
            {
                using (SqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandType = cmdType;
                    cmd.CommandText = CommandName;
                    cmd.Parameters.AddRange(param);

                    try
                    {
                        if (con.State != ConnectionState.Open)
                        {
                            con.Open();
                        }

                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            da.Fill(table);
                        }
                    }
                    catch
                    {
                        throw;
                    }
                }
            }

            return table;
        }
Example #8
0
 /// <summary>
 /// execute a query£¬return DataSet
 /// </summary>
 /// <param name="SQLString"></param>
 /// <returns>DataSet</returns>
 public static DataSet Query(string connectionString, CommandType cmdType, string SQLString, params OracleParameter[] cmdParms)
 {
     using (OracleConnection connection = new OracleConnection(connectionString))
     {
         OracleCommand cmd = new OracleCommand();
         PrepareCommand(cmd, connection, null, cmdType, SQLString, cmdParms);
         using (OracleDataAdapter da = new OracleDataAdapter(cmd))
         {
             DataSet ds = new DataSet();
             //try
             //{
                 da.Fill(ds, "ds");
                 cmd.Parameters.Clear();
             //}
             //catch (System.Data.OracleClient.OracleException ex)
             //{
             //    throw new Exception(ex.Message);
             //}
             //finally
             //{
             //    if (connection.State != ConnectionState.Closed)
             //    {
             //        connection.Close();
             //    }
             //}
             return ds;
         }
     }
 }
Example #9
0
 /// <summary>
 /// 1.带参数查询,返回bool,直接SQL语句
 /// </summary>
 /// <param name="sqlTypeString"></param>
 /// <param name="cmdType"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public static bool CheckIsExist(string sqlTypeString, CommandType cmdType, params SqlParameter[] parameters)
 {
     bool flag = false;
     SqlDataReader reader = null;
     try
     {
         using (SqlCommand cmd = new SqlCommand(sqlTypeString, Connection))
         {
             cmd.CommandType = cmdType;
             cmd.Parameters.AddRange(parameters);
             reader = cmd.ExecuteReader();
             if (reader.HasRows && reader.Read())
             {
                 flag = true;
             }
         }
     }
     catch (SqlException ex)
     {
         flag = false;
         throw ex;
     }
     finally
     {
         if (reader != null) reader.Close();
     }
     return flag;
 }
Example #10
0
 public static DataTable ExecuteData(CommandType cmdCommandType, string cmdCommandString, params SqlParameter[] cmdParameters)
 {
     SqlCommand cmdCommand = new SqlCommand();
     SqlConnection connect = new SqlConnection(ConnectionString.Text);
     try
     {
         DataTable dattTopic = new DataTable();
         SqlDataAdapter dataTopic = new SqlDataAdapter(cmdCommand);
         PrepareCommand(cmdCommand, connect, null, cmdCommandType, cmdCommandString, cmdParameters);
         cmdCommand.ExecuteNonQuery();
         dataTopic.Fill(dattTopic);
         cmdCommand.Parameters.Clear();
         if (connect.State == ConnectionState.Open) connect.Close();
         return dattTopic;
     }
     catch (SqlException ex)
     {
         if (connect.State == ConnectionState.Open)
         {
             connect.Close();
             SqlConnection.ClearPool(connect);
         }
         throw ex;
     }
 }
Example #11
0
        public SqlCommand GetDBCommand(SqlConnection sqlcn, String CmdText, CommandType CmdType, CommandBehavior CmdBehavior, SqlParameter[] sqlParam)
        {
            SqlCommand sqlcmd = null;

            try
            {
                sqlcmd = new SqlCommand(CmdText, sqlcn);
                sqlcmd.CommandType = CmdType;

                sqlcmd.CommandTimeout = GetCommandTimeout();

                Utilities.DebugLogging.Log("CONNECTION STRING " + sqlcn.ConnectionString);
                Utilities.DebugLogging.Log("COMMAND TEXT " + CmdText);
                Utilities.DebugLogging.Log("COMMAND TYPE " + CmdType.ToString());
                if (sqlParam != null)
                    Utilities.DebugLogging.Log("NUMBER OF PARAMS " + sqlParam.Length);

                AddSQLParameters(sqlcmd, sqlParam);

            }
            catch (Exception ex)
            {
                Utilities.DebugLogging.Log(ex.Message);
                Utilities.DebugLogging.Log(ex.StackTrace);
            }
            return sqlcmd;
        }
Example #12
0
    protected override void HandleObjectCommand(CommandType command, GameObject targetObject)
    {
        if (isSelected)
        {
            switch (command)
            {
                case CommandType.Attack:
                    {
                        currentTarget = targetObject.GetComponent<Commandable>();
                        currentCommand = command;
                        UpdatePath();
                    }
                    break;
                case CommandType.Follow:
                    {

                    }
                    break;
                case CommandType.Patrol:
                    {

                    }
                    break;
                case CommandType.Mine:
                    {
                        currentResourceTarget = targetObject.GetComponent<Resource>();
                        currentCommand = command;
                        UpdatePath();
                    }
                    break;
                default:
                    break;
            }
        }
    }
Example #13
0
 /// <summary>
 /// 查询操作方法
 /// </summary>
 /// <param name="sql">执行的sql语句</param>
 /// <param name="cmdType">sql语句类型</param>
 /// <param name="paras">传入的参数</param>
 /// <returns>返回执行结果的首行首列</returns>
 public static object ExecuteScalar(string sql, CommandType cmdType, params SqlParameter[] paras)
 {
     using (SqlConnection conn = new SqlConnection(serverPath))
     {
         using (SqlCommand cmd = new SqlCommand(sql, conn))
         {
             if (paras != null)
             {
                 cmd.Parameters.AddRange(paras);
             }
             cmd.CommandType = cmdType;
             try
             {
                 conn.Open();
                 return cmd.ExecuteScalar();
             }
             catch (Exception ex)
             {
                 conn.Close();
                 conn.Dispose();
                 throw ex;
             }
         }
     }
 }
Example #14
0
 public ChatMessage(MessageType type, CommandType command, string channel, string message)
 {
     this.message = message;
     this.type = (int)type;
     this.channel = channel;
     this.command = (int)command;
 }
Example #15
0
        public bool ExecuteNonQuery(string CommandName, CommandType cmdType, SqlParameter[] pars)
        {
            SqlCommand cmd = null;
            int res = 0;

            cmd = con.CreateCommand();

            cmd.CommandType = cmdType;
            cmd.CommandText = CommandName;
            cmd.Parameters.AddRange(pars);

            try
            {
                con.Open();

                res = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Dispose();
                cmd = null;
                con.Close();
            }

            if (res >= 1)
            {
                return true;
            }
            return false;
        }
Example #16
0
 //返回SqlDataReader的方法
 public static SqlDataReader ExecuteReader(String sql, CommandType cmdType, params SqlParameter[] pms)
 {
     //连接对象
         SqlConnection con = new SqlConnection(constr);
             //执行命令
             using (SqlCommand cmd = new SqlCommand(sql, con))
             {
                 cmd.CommandType = cmdType;
                 if (pms != null)
                 {
                     cmd.Parameters.AddRange(pms);
                 }
                 try
                 {
                     con.Open();
                     // sqldata关掉不能用
                     return cmd.ExecuteReader(CommandBehavior.CloseConnection);
                 }
                 catch
                 {
                     //关闭连接
                     con.Close();
                     //释放连接
                     con.Dispose();
                     throw;
                 }
             }
 }
Example #17
0
		/// <summary>
		/// Start a new command of a speicifc type with a global and/or local buffer on the EV3 brick
		/// </summary>
		/// <param name="commandType">The type of the command to start</param>
		/// <param name="globalSize">The size of the global buffer in bytes (maximum of 1024 bytes)</param>
		/// <param name="localSize">The size of the local buffer in bytes (maximum of 64 bytes)</param>
		public void Initialize(CommandType commandType, ushort globalSize, int localSize)
		{
			if(globalSize > 1024)
				throw new ArgumentException("Global buffer must be less than 1024 bytes", "globalSize");
			if(localSize > 64)
				throw new ArgumentException("Local buffer must be less than 64 bytes", "localSize");

			_stream = new MemoryStream();
			_writer = new BinaryWriter(_stream);
			Response = ResponseManager.CreateResponse();

			CommandType = commandType;

			// 2 bytes (this gets filled in later when the user calls ToBytes())
			_writer.Write((ushort)0xffff);

			// 2 bytes
			_writer.Write(Response.Sequence);

			// 1 byte
			_writer.Write((byte)commandType);

			if(commandType == CommandType.DirectReply || commandType == CommandType.DirectNoReply)
			{
				// 2 bytes (llllllgg gggggggg)
				_writer.Write((byte)globalSize); // lower bits of globalSize
				_writer.Write((byte)((localSize << 2) | (globalSize >> 8) & 0x03)); // upper bits of globalSize + localSize
			}
		}
Example #18
0
        /// <summary>
        /// Execute a SqlCommand that returns a resultset against the database specified in the connection string 
        /// using the provided parameters.
        /// </summary>
        /// <remarks>
        /// e.g.:  
        ///  DataSet ds = ExecuteAdapter(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">a valid connection string for a SqlConnection</param>
        /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        /// <param name="commandText">the stored procedure name or T-SQL command</param>
        /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        /// <returns>A Dataset containing the results</returns>
        public static DataSet ExecuteAdapter(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand();
            SqlConnection conn = new SqlConnection(connectionString);

            // we use a try/catch here because if the method throws an exception we want to
            // close the connection throw code, because no datareader will exist, hence the
            // commandBehaviour.CloseConnection will not work
            try
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    da.Fill(ds);
                    cmd.Parameters.Clear();
                    conn.Close();
                    //added by lk in 2010-05-21 begin
                    foreach (DataTable dt in ds.Tables)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            foreach (DataColumn dc in dt.Columns)
                            {
                                if (dc.DataType == Type.GetType("System.String"))
                                {
                                    // NULL -> ""; + TRIM()
                                    dr[dc] = dr[dc].ToString().Trim();
                                }
                                else if (dc.DataType == Type.GetType("System.DateTime"))
                                {
                                    if (Convert.IsDBNull(dr[dc]) || dr[dc].ToString().Equals(""))
                                    {
                                        dr[dc] = DateTime.MinValue;
                                    }
                                }
                                else if (dc.DataType == Type.GetType("System.Decimal") || dc.DataType == Type.GetType("System.Int32") || dc.DataType == Type.GetType("System.Int64"))
                                {
                                    if (Convert.IsDBNull(dr[dc]))
                                    {
                                        dr[dc] = 0;
                                    }
                                }

                            }
                        }
                    }
                    //added by lk in 2010-05-21 end
                    return ds;
                }
            }
            catch
            {
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
                throw;
            }
        }
 internal LocalCommand(string commandText, SqlParameterCollection parameters,  int returnParameterIndex, CommandType cmdType) {
     Debug.Assert(0 <= commandText.Length, "no text");
     this.CommandText = commandText;
     this.Parameters = parameters;
     this.ReturnParameterIndex = returnParameterIndex;
     this.CmdType = cmdType;
 }
Example #20
0
		private static void ExecuteCommand(CommandType command, DirectoryInfo baseDirectory, Lazy<Uri> url, string userName, string password) 
		{
			var engine = Engine.CreateStandard(baseDirectory);
			switch (command)
			{
				case CommandType.Help:
					break;
				case CommandType.Generate:
					var generatedDocuments = engine.Generate();
					foreach (var generatedDocument in generatedDocuments)
					{
						System.Console.WriteLine(generatedDocument);
						System.Console.WriteLine();
					}
					break;
				case CommandType.Check:
					var haveChanged =
						engine.CheckIfChanged(url.Value, userName, password);
					System.Console.WriteLine(haveChanged? "Changed": "Have not changed");
					break;
				case CommandType.Push:
					engine.PushIfChanged(url.Value, userName, password);
					break;
				case CommandType.Purge:
					engine.PurgeDatabase(url.Value, userName, password);
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}
		}
        internal static void PrepareCommand(SQLiteCommand command, SQLiteConnection connection, SQLiteTransaction transaction,
                                           CommandType commandType, string commandText, SQLiteParameter[] commandParameters,
                                           out bool mustCloseConnection)
        {
            if (command == null) throw new ArgumentNullException("command");
            if (string.IsNullOrEmpty(commandText)) throw new ArgumentNullException("commandText");

            if (connection.State == ConnectionState.Open)
                mustCloseConnection = false;
            else
            {
                mustCloseConnection = true;
                connection.Open();
            }

            command.Connection = connection;
            command.CommandText = commandText;

            if (transaction != null)
            {
                if (transaction.Connection == null)
                    throw new ArgumentException(
                        "The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
                command.Transaction = transaction;
            }

            command.CommandType = commandType;

            if (commandParameters != null)
                AttachParameters(command, commandParameters);
            return;
        }
        /// <summary>
        ///     Constructs a SqlCommand with the given parameters. This method is normally called
        ///     from the other methods and not called directly. But here it is if you need access
        ///     to it.
        /// </summary>
        /// <param name="qry">SQL query or stored procedure name</param>
        /// <param name="type">Type of SQL command</param>
        /// <param name="args">
        ///     Query arguments. Arguments should be in pairs where one is the
        ///     name of the parameter and the second is the value. The very last argument can
        ///     optionally be a SqlParameter object for specifying a custom argument type
        /// </param>
        /// <returns></returns>
        public SqlCommand CreateCommand(string qry, CommandType type, params object[] args)
        {
            var cmd = new SqlCommand(qry, Conn);

            // Associate with current transaction, if any
            if (Trans != null)
                cmd.Transaction = Trans;

            // Set command type
            cmd.CommandType = type;

            // Construct SQL parameters
            for (var i = 0; i < args.Length; i++)
            {
                if (args[i] is string && i < (args.Length - 1))
                {
                    var parm = new SqlParameter();
                    parm.ParameterName = (string) args[i];
                    parm.Value = args[++i];
                    cmd.Parameters.Add(parm);
                }
                else if (args[i] is SqlParameter)
                {
                    cmd.Parameters.Add((SqlParameter) args[i]);
                }
                else throw new ArgumentException("Invalid number or type of arguments supplied");
            }
            return cmd;
        }
 /// <summary>
 /// 执行数据库查询,返回DataSet对象
 /// </summary>
 /// <param name="connectionString">连接字符串</param>
 /// <param name="commandText">执行语句或存储过程名</param>
 /// <param name="commandType">执行类型</param>
 /// <returns>DataSet对象</returns>
 public DataSet ExecuteDataSet(string connectionString, string commandText, CommandType commandType)
 {
     if (connectionString == null || connectionString.Length == 0)
         throw new ArgumentNullException("connectionString");
     if (commandText == null || commandText.Length == 0)
         throw new ArgumentNullException("commandText");
     DataSet ds = new DataSet();
     SQLiteConnection con = new SQLiteConnection(connectionString);
     SQLiteCommand cmd = new SQLiteCommand();
     SQLiteTransaction trans = null;
     PrepareCommand(cmd, con, ref trans, false, commandType, commandText);
     try
     {
         SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
         sda.Fill(ds);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (con != null)
         {
             if (con.State == ConnectionState.Open)
             {
                 con.Close();
             }
         }
     }
     return ds;
 }
		private int Process(CommandType command)
		{
			var options = new Options { DatabaseUrl = DatabaseUrl.Text, BaseDirectory = BaseDirectory.Text, Command = command };

			var directoryPath = !string.IsNullOrWhiteSpace(options.BaseDirectory) ? options.BaseDirectory : Environment.CurrentDirectory;

			var baseDirectory = new DirectoryInfo(directoryPath);
			if (!baseDirectory.Exists)
			{
				MessageBox.Show(@"Provided directory {0} does not exist.", options.BaseDirectory);
				return IncorrectOptionsReturnCode;
			}

			var password = Environment.GetEnvironmentVariable(PasswordEnvVar);
			var url = new Lazy<Uri>(() => ParseDatabaseUrl(options));

			try
			{
				ExecuteCommand(options.Command, baseDirectory, url, password);
			}
			catch (Exception e)
			{
				MessageBox.Show(e.ToString());
				return UnknownErrorReturnCode;
			}

			return OkReturnCode;
		}
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="type"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string cmd, CommandType type, CommandCallback callback)
        {
            // Is it a console command?
            if (type == CommandType.Console) return;

            // Convert to lowercase
            var command_name = cmd.ToLowerInvariant();

            // Check if it already exists
            if (CommandManager.RegisteredCommands.ContainsKey(command_name))
            {
                throw new CommandAlreadyExistsException(command_name);
            }

            // Register it
            var commandAttribute = new CommandAttribute("/" + command_name, string.Empty)
            {
                Method = info =>
                {
                    var player = HurtworldCovalenceProvider.Instance.PlayerManager.GetPlayer(info.PlayerId.ToString());
                    callback(info.Label, CommandType.Chat, player, info.Args);
                }
            };
            CommandManager.RegisteredCommands[command_name] = commandAttribute;
        }
Example #26
0
        /// <summary>
        /// Gets a data reader.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="commandType">Type of the command.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public static IDataReader GetDataReader( string query, CommandType commandType, Dictionary<string, object> parameters )
        {
            string connectionString = GetConnectionString();
            if ( !string.IsNullOrWhiteSpace( connectionString ) )
            {
                SqlConnection con = new SqlConnection( connectionString );
                con.Open();

                SqlCommand sqlCommand = new SqlCommand( query, con );
                sqlCommand.CommandType = commandType;

                if ( parameters != null )
                {
                    foreach ( var parameter in parameters )
                    {
                        SqlParameter sqlParam = new SqlParameter();
                        sqlParam.ParameterName = parameter.Key.StartsWith( "@" ) ? parameter.Key : "@" + parameter.Key;
                        sqlParam.Value = parameter.Value;
                        sqlCommand.Parameters.Add( sqlParam );
                    }
                }

                return sqlCommand.ExecuteReader( CommandBehavior.CloseConnection );
            }

            return null;
        }
        /// <summary>
        /// 返回DataSet
        /// </summary>
        /// <param name="cmdText">命令字符串</param>
        /// <param name="cmdType">命令类型</param>
        /// <param name="commandParameters">可变参数</param>
        /// <returns> DataSet </returns>
        public static DataSet ExecuteDataSet(string cmdText, CommandType cmdType, params MySqlParameter[] commandParameters)
        {
            DataSet result = null;

            using (MySqlConnection conn = GetConnection)
            {
                try
                {
                    MySqlCommand command = new MySqlCommand();
                    PrepareCommand(command, conn, cmdType, cmdText, commandParameters);
                    MySqlDataAdapter adapter = new MySqlDataAdapter();
                    adapter.SelectCommand = command;
                    result = new DataSet();
                    adapter.Fill(result);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    if (conn != null && conn.State != ConnectionState.Closed)
                        conn.Close();
                }
            }

            return result;
        }
Example #28
0
        public static DataTable Execute_DataTable(SqlParameter[] prm, string Query, string TableName, CommandType CmnType,SqlConnection con)
        {
            dt = new DataTable(TableName);
            cmn = new SqlCommand();
            cmn.CommandType = CmnType;
            cmn.CommandText = Query.Replace("@DbName", SCMDBNAME).Replace("@FrmNo", FRMNO).Replace("@DnmNo", DNMNO);
            cmn.Connection = con;
            foreach (SqlParameter item in prm)
            {
                cmn.Parameters.AddWithValue(item.ParameterName, item.Value);
            }
            try
            {

                adp = new SqlDataAdapter(cmn);
                adp.Fill(dt);
                cmn.Dispose();
                adp.Dispose();
            }
            catch (Exception ex)
            {

                cmn.Dispose();
                adp.Dispose();

            }
            return dt;
        }
Example #29
0
 /// <summary>
 /// Create a new Command object for the given destination, type, and optional argument.
 /// </summary>
 /// <param name="destination">a ZObject that denotes the destination for this command</param>
 /// <param name="type">the CommandType of the new command</param>
 /// <param name="arg">an Object to comprise the argument for the command (optional)</param>
 public Command([CanBeNull] ZObject destination, CommandType type, [CanBeNull] object arg = null)
     : this()
 {
     Destination = destination;
     CommandType = type;
     Arg = arg;
 }
Example #30
0
 public abstract XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText);
Example #31
0
        ////////////////////////////////////////////////////////////////////////
        // ExecuteDataSet Methods
        ////////////////////////////////////////////////////////////////////////
        protected DataSet ExecuteDataSet(string cmdText, CommandType cmdType, params IDataParameter[] procParams)
        {
            SqlCommand cmd;

            return(ExecuteDataSet(out cmd, cmdText, cmdType, procParams));
        }
Example #32
0
        private DbCommand GetCommand(DbConnection conn, string cmdText, IDbDataParameter[] parameters = null, CommandType cmdType = CommandType.Text)
        {
            using var cmd = conn.CreateCommand();
            cmd.CommandText = cmdText;
            cmd.CommandType = cmdType;
            if (parameters != null)
                cmd.Parameters.AddRange(parameters);

            return cmd;
        }
    /// <summary>
    /// 准备执行一个命令
    /// </summary>
    /// <param name="cmd">sql命令</param>
    /// <param name="conn">OleDb连接</param>
    /// <param name="trans">OleDb事务</param>
    /// <param name="cmdType">命令类型例如 存储过程或者文本</param>
    /// <param name="cmdText">命令文本,例如:Select * from Products</param>
    /// <param name="cmdParms">执行命令的参数</param>
    private static void PrepareCommand(MySqlCommand cmd, MySqlConnection conn, MySqlTransaction trans, CommandType cmdType, string cmdText, MySqlParameter[] cmdParms)
    {
        if (conn.State != ConnectionState.Open)
        {
            conn.Open();
        }

        cmd.Connection  = conn;
        cmd.CommandText = cmdText;

        if (trans != null)
        {
            cmd.Transaction = trans;
        }

        cmd.CommandType = cmdType;

        if (cmdParms != null)
        {
            foreach (MySqlParameter parm in cmdParms)
            {
                cmd.Parameters.Add(parm);
            }
        }
    }
Example #34
0
 protected override DataTable GetProcedureSchema(DataConnection dataConnection, string commandText, CommandType commandType, DataParameter[] parameters)
 {
     try
     {
         return(base.GetProcedureSchema(dataConnection, commandText, commandType, parameters));
     }
     catch (Exception ex)
     {
         if (ex.Message.Contains("SQL error code = -84"))                 // procedure XXX does not return any values
         {
             return(null);
         }
         throw;
     }
 }
Example #35
0
        private void PrepareCommand(IDbCommand command, IDbConnection connection, IDbTransaction transaction, CommandType commandType, string commandText, IDbDataParameter[] commandParameters)
        {
            //command.Connection = connection;
            //command.CommandText = commandText;
            //command.CommandType = commandType;


            //if (transaction != null)
            //{
            //    command.Transaction = transaction;
            //}

            //if (commandParameters != null)
            //{
            //    AttachParameters(command, commandParameters);
            //}

            try
            {
                if (providerType == DataProvider.SqlServer && commandText != null && commandText != "" && commandText.IndexOf("set dateformat dmy") == -1 && commandType != CommandType.StoredProcedure)
                {
                    commandText = "set dateformat dmy " + commandText;
                }


                command.Connection     = connection;
                command.CommandText    = commandText;
                command.CommandType    = commandType;
                command.CommandTimeout = 300;

                if (transaction != null)
                {
                    command.Transaction = transaction;
                }

                if (commandParameters != null)
                {
                    AttachParameters(command, commandParameters);
                }
                else
                {
                    //Dongpv:22/04/2018
                    LogMessage.Trace(commandText + "\n", "TRANCE_SQL");
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.ThrowError(ex);
            }
        }
Example #36
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ID != 0L)
            {
                hash ^= ID.GetHashCode();
            }
            if (CommandType != 0)
            {
                hash ^= CommandType.GetHashCode();
            }
            if (MoveDirection != 0)
            {
                hash ^= MoveDirection.GetHashCode();
            }
            if (MoveDuration != 0)
            {
                hash ^= MoveDuration.GetHashCode();
            }
            if (ThrowDistance != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(ThrowDistance);
            }
            if (ThrowAngle != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(ThrowAngle);
            }
            if (IsThrowDish != false)
            {
                hash ^= IsThrowDish.GetHashCode();
            }
            if (UseType != 0)
            {
                hash ^= UseType.GetHashCode();
            }
            if (SpeakText.Length != 0)
            {
                hash ^= SpeakText.GetHashCode();
            }
            if (Parameter1 != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Parameter1);
            }
            if (Parameter2 != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Parameter2);
            }
            if (IsSetTalent != false)
            {
                hash ^= IsSetTalent.GetHashCode();
            }
            if (Talent != 0)
            {
                hash ^= Talent.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Example #37
0
        public static DbCommand SetCommandParameters(this DbCommand cmd, string command, CommandType type, int?timeout)
        {
#pragma warning disable CA2100 // Review SQL queries for security vulnerabilities
            cmd.CommandText = command;
#pragma warning restore CA2100 // Review SQL queries for security vulnerabilities
            cmd.CommandType = type;
            if (timeout != null)
            {
                cmd.CommandTimeout = timeout.Value;
            }

            return(cmd);
        }
Example #38
0
 public async Task ExecuteReaderAsync(string cmdText, IEnumerable<DBReaderHandler> readerHandlers, IDbDataParameter[] parameters = null, CommandType cmdType = CommandType.Text)
 {
     using var conn = GetConnection();
     using var cmd = GetCommand(conn, cmdText, parameters, cmdType);
     using var reader = await cmd.ExecuteReaderAsync();
     foreach (var handler in readerHandlers)
     {
         if (handler.IsFirstResult || (!handler.IsFirstResult && await reader.NextResultAsync()))
             while (await reader.ReadAsync())
                 handler.Handler.Invoke(reader);
     }
 }
Example #39
0
 public async Task<object> ExecuteScalarAsync(string cmdText, IDbDataParameter[] parameters = null, CommandType cmdType = CommandType.Text)
 { 
     using var conn = GetConnection();
     return await GetCommand(conn, cmdText, parameters, cmdType).ExecuteScalarAsync();
 }
Example #40
0
 public T Get <T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.Text)
 {
     using IDbConnection db = new SqlConnection(this.config.GetConnectionString(this.connectionstring));
     return(db.Query <T>(sp, parms, commandType: commandType).FirstOrDefault());
 }
Example #41
0
 public List <T> GetAll <T>(string sp, object parms, CommandType commandType = CommandType.StoredProcedure)
 {
     using IDbConnection db = new SqlConnection(this.config.GetConnectionString(this.connectionstring));
     return(db.Query <T>(sp, parms, commandType: commandType).ToList());
 }
Example #42
0
        public void GetSQLMultipleData <T1, T2, T3, T4, T5, T6>(string sql, List <T1> t1, List <T2> t2 = null,
                                                                List <T3> t3      = null, List <T4> t4     = null, List <T5> t5 = null, List <T6> t6 = null,
                                                                object parameters = null, CommandType type = CommandType.StoredProcedure)
        {
            parameters = TransformArrayParametersToTableValuedParameters(parameters);

            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings[_connectionString].ConnectionString))
            {
                conn.Open();
                var res = conn.QueryMultiple(sql, parameters, commandType: type);
                t1.AddRange(res.Read <T1>());
                if (t2 != null)
                {
                    t2.AddRange(res.Read <T2>());
                }
                if (t3 != null)
                {
                    t3.AddRange(res.Read <T3>());
                }
                if (t4 != null)
                {
                    t4.AddRange(res.Read <T4>());
                }
                if (t5 != null)
                {
                    t5.AddRange(res.Read <T5>());
                }
                if (t6 != null)
                {
                    t6.AddRange(res.Read <T6>());
                }
            }
        }
Example #43
0
 private static void PrepareCommand(SqlConnection conn, SqlCommand cmd, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] commandParameters)
 {
     if (conn.State != ConnectionState.Open)
     {
         conn.Open();
     }
     cmd.Connection  = conn;
     cmd.CommandText = cmdText;
     if (trans != null)
     {
         cmd.Transaction = trans;
     }
     cmd.CommandType = cmdType;
     if (commandParameters != null)
     {
         AttachParameters(cmd, commandParameters);
     }
 }
Example #44
0
 public static void db2PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, CommandType cmdType, string cmdText, OleDbParameter[] cmdParms)
 {
     try
     {
         if (conn.State != ConnectionState.Open)
         {
             try
             {
                 conn.Open();
             }
             catch (Exception exception)
             {
                 Log4netHelper.Error(exception, "db2error", "db2Openerror");
             }
         }
         cmd.Connection  = conn;
         cmd.CommandText = cmdText;
         if (trans != null)
         {
             cmd.Transaction = trans;
         }
         cmd.CommandType = cmdType;
         if (cmdParms != null)
         {
             foreach (OleDbParameter parameter in cmdParms)
             {
                 cmd.Parameters.Add(parameter);
             }
         }
     }
     catch (Exception exception2)
     {
         Log4netHelper.Error(exception2, "db2error", "db2Commanderror");
     }
 }
Example #45
0
 public void GetSQLMultipleData <T1, T2>(string sql, List <T1> t1, List <T2> t2 = null,
                                         object parameters = null, CommandType type = CommandType.StoredProcedure)
 {
     GetSQLMultipleData <T1, T2, int, int, int, int>(sql, t1, t2, null, null, null, null,
                                                     parameters, type);
 }
 public int Delete(string sqlQuery, DynamicParameters param, CommandType commandType)
 {
     return(_businessRepository.Delete(sqlQuery, param, commandType));
 }
Example #47
0
 private static void Connection_UnknownCommandReceived(CommandType cmdType, uint cmdId, uint cmdVer, byte[] data)
 {
     Console.WriteLine("Unknown command received");
 }
Example #48
0
 public abstract object ExecuteScalar(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters);
Example #49
0
 public abstract XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters);
Example #50
0
 public abstract object ExecuteScalar(string connectionString, CommandType commandType, string commandText);
Example #51
0
        public bool MyExecuteNonQuery(ref string err, ref int rows, string commandText, CommandType commandType, params SqlParameter[] param)
        {
            bool result = false;

            try
            {
                //Mo ket noi
                if (connect.State == ConnectionState.Open)
                {
                    connect.Close();
                }
                connect.Open();
                //khoi tao command
                command = new SqlCommand()
                {
                    Connection     = connect,
                    CommandText    = commandText,
                    CommandType    = commandType,
                    CommandTimeout = 600
                };
                if (param != null)
                {
                    foreach (SqlParameter item in param)
                    {
                        command.Parameters.Add(item);
                    }
                }
                rows   = command.ExecuteNonQuery();
                result = true;
            }
            catch (Exception ex) { err = ex.Message; }
            finally { connect.Close(); }// dung dong ket noi
            return(result);
        }
Example #52
0
 public abstract SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText);
Example #53
0
 public abstract XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText);
Example #54
0
 public abstract SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText);
Example #55
0
 public abstract object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters);
Example #56
0
 public abstract SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters);
Example #57
0
 public abstract SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters);
Example #58
0
 public abstract object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText);
Example #59
0
 public abstract object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText);
Example #60
-1
        private static void PrepareCommand(
            DbCommand command,
            DbConnection connection,
            DbTransaction transaction,
            CommandType commandType,
            string commandText,
            DbParameter[] commandParameters)
        {
            if (command == null) throw new ArgumentNullException("command");
            if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText");

            command.Connection = connection;
            command.CommandText = commandText;
            command.CommandType = commandType;

            if (transaction != null)
            {
                if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
                command.Transaction = transaction;
            }

            if (commandParameters != null)
            {
                AttachParameters(command, commandParameters);
            }
            return;
        }