C# (CSharp) CommandType примеры использования

C# (CSharp) CommandType - 30 примеров найдено. Это лучшие примеры C# (CSharp) кода для CommandType, полученные из open source проектов. Вы можете ставить оценку каждому примеру, чтобы помочь нам улучшить качество примеров.
Основные методы
Пример #1
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;
            }
        }
    }
Пример #2
0
        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();
            }
        }
Пример #3
0
        // 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);
        }
Пример #4
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;
 }
Пример #5
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;
            }
        }
Пример #6
0
        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;
        }
        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;
        }
Пример #8
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;
        }
        /// <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;
 }
Пример #11
0
		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;
		}
Пример #12
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;
     }
 }
Пример #13
0
        /// <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;
        }
Пример #14
0
        /// <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;
        }
Пример #15
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;
             }
         }
     }
 }
Пример #16
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;
        }
Пример #17
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;
        }
Пример #18
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();
		}
	}
Пример #19
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;
 }
Пример #20
0
        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;
        }
Пример #21
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;
 }
Пример #22
0
        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;
        }
Пример #23
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;
        }
Пример #24
0
 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;
 }
Пример #25
0
        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;
        }
Пример #26
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;
                 }
             }
 }
Пример #27
0
        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();
            }
        }
Пример #28
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
			}
		}
Пример #29
0
        // 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;
        }
Пример #30
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;
         }
     }
 }