• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CommandType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CommandType的典型用法代码示例。如果您正苦于以下问题:C# CommandType类的具体用法?C# CommandType怎么用?C# CommandType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CommandType类属于命名空间,在下文中一共展示了CommandType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ConvertToNativeParameter

        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;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:33,代码来源:OracleCommandBuilder.cs


示例2: ExecuteNonQuery

        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();
            }
        }
开发者ID:hbb20,项目名称:gtu_pde,代码行数:26,代码来源:DataAccess.cs


示例3: ExecuteParamerizedSelectCommand

        // 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;
        }
开发者ID:kma14,项目名称:AC,代码行数:34,代码来源:SqlDBHelper.cs


示例4: ExecuteDataSet

        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();
            }
        }
开发者ID:hbb20,项目名称:gtu_pde,代码行数:29,代码来源:DataAccess.cs


示例5: ExecuteNonQuery

        // 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);
        }
开发者ID:kma14,项目名称:AC,代码行数:30,代码来源:SqlDBHelper.cs


示例6: GenerateCommand

        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;
        }
开发者ID:huayang912,项目名称:cs-dotnetnuke,代码行数:29,代码来源:SqlCommandGenerator.cs


示例7: ExecuteNonQuery

        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;
        }
开发者ID:jvillalta696,项目名称:ILACCSharp,代码行数:34,代码来源:ADODataAccess.cs


示例8: ExecuteScalar

 /// <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;
             }
         }
     }
 }
开发者ID:fqncom,项目名称:tomcraporigami,代码行数:32,代码来源:SqlHelper.cs


示例9: ExecuteData

 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;
     }
 }
开发者ID:gjundat95,项目名称:Console,代码行数:25,代码来源:DataAccess.cs


示例10: ExecuteAdapter

        /// <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;
            }
        }
开发者ID:marcpiulachs,项目名称:noahylk,代码行数:73,代码来源:DBAccess.cs


示例11: CheckIsExist

 /// <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;
 }
开发者ID:caideyuan,项目名称:ObsidianToolkit,代码行数:35,代码来源:MSSqlHelper.cs


示例12: ExecuteCommand

		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();
			}
		}
开发者ID:artikh,项目名称:CouchDude.SchemeManager,代码行数:30,代码来源:Program.cs


示例13: GetDataReader

        /// <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;
        }
开发者ID:Ganon11,项目名称:Rock,代码行数:34,代码来源:DbService.cs


示例14: CreateCommand

        /// <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;
        }
开发者ID:rohanbaraskar,项目名称:SeleniumAutomationFramework,代码行数:42,代码来源:SqlHelper.cs


示例15: Execute_DataTable

        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;
        }
开发者ID:muratsuzen,项目名称:MobileShop,代码行数:28,代码来源:DataClass.cs


示例16: Process

		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;
		}
开发者ID:artikh,项目名称:CouchDude.SchemeManager,代码行数:28,代码来源:MainForm.cs


示例17: ExecuteDataSet

 /// <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;
 }
开发者ID:GininDev,项目名称:ServicesInforCollector,代码行数:39,代码来源:SQLiteHelper.cs


示例18: ExecuteParamerizedSelectCommand

        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;
        }
开发者ID:jvillalta696,项目名称:ILACCSharp,代码行数:34,代码来源:ADODataAccess.cs


示例19: Command

 /// <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;
 }
开发者ID:somdoron,项目名称:netmq,代码行数:13,代码来源:Command.cs


示例20: PrepareCommand

        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;
        }
开发者ID:sreenandini,项目名称:test_buildscripts,代码行数:32,代码来源:SQLiteHelper.cs



注:本文中的CommandType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Commands类代码示例发布时间:2022-05-24
下一篇:
C# CommandTarget类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap