当前位置: 首页>>代码示例>>C#>>正文


C# DbCommand.ExecuteNonQuery方法代码示例

本文整理汇总了C#中DbCommand.ExecuteNonQuery方法的典型用法代码示例。如果您正苦于以下问题:C# DbCommand.ExecuteNonQuery方法的具体用法?C# DbCommand.ExecuteNonQuery怎么用?C# DbCommand.ExecuteNonQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbCommand的用法示例。


在下文中一共展示了DbCommand.ExecuteNonQuery方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteNonQuery

 public int ExecuteNonQuery(DbCommand cmd)
 {
     DbConnection conn = null;
     try {
         conn = this.GetOpenConnection();
         cmd.Connection = conn;
         return cmd.ExecuteNonQuery();
     } finally {
         this.ReleaseConnection(conn);
     }
 }
开发者ID:ChristophWurst,项目名称:UFO,代码行数:11,代码来源:Database.cs

示例2: ExecuteNonQuery

 //public static int ExecuteNonQuery(string queryText)
 //{
 //    switch (DatabaseSettings.DbType)
 //    {
 //        case Enums.DatabaseType.MsSQL:
 //            using (SqlConnection sq = new SqlConnection(DatabaseSettings.ConnectionString))
 //            {
 //                sq.Open();
 //                using (SqlCommand sc = new SqlCommand(queryText, sq))
 //                {
 //                    return sc.ExecuteNonQuery();
 //                }
 //            }
 //        case Enums.DatabaseType.MySQL:
 //            using (MySqlConnection sq = new MySqlConnection(DatabaseSettings.ConnectionString))
 //            {
 //                sq.Open();
 //                using (MySqlCommand sc = new MySqlCommand(queryText, sq))
 //                {
 //                    return sc.ExecuteNonQuery();
 //                }
 //            }
 //        default:
 //            return 0;
 //    }
 //}
 public static int ExecuteNonQuery(DbCommand query, DbConnection dc)
 {
     switch (DatabaseSettings.DbType)
     {
         case Enums.DatabaseType.MsSQL:
         case Enums.DatabaseType.MySQL:
             using (query)
             {
                 query.Connection = dc;
                 return query.ExecuteNonQuery();
             }
         default:
             return -1;
     }
 }
开发者ID:Pikanius,项目名称:chanb,代码行数:41,代码来源:DatabaseEngine.cs

示例3: NonQuery

 //----------------------------------------------------------------------------------------------------
 /// <summary>
 /// 쿼리 요청 ( UPDATE, INSERT, DELETE ... )
 /// </summary>
 /// <param name="sql">SQL문</param>
 /// <returns>성공 유무</returns>
 //----------------------------------------------------------------------------------------------------
 public bool NonQuery( string sql )
 {
     try
     {
         CloseQuery();
         m_command = m_connection.CreateCommand();
         m_command.CommandType = CommandType.Text;
         m_command.CommandText = sql;
         m_command.ExecuteNonQuery();
         CloseQuery();
         return true;
     }
     catch( Exception ex )
     {
         Log( ex.ToString() );
         m_error = ex.Message;
         CloseQuery();
         return false;
     }
 }
开发者ID:qipa,项目名称:BluemoonServer,代码行数:27,代码来源:cDatabase.cs

示例4: Update11Relation

		private void Update11Relation(IDictionary<IDbObject, long> objectGraph, IDbObject o, DbConnection connection, RelationInfo relation, DbCommand command, string mappingTable, List<long> persistentRelation, PropertyInfo propertyInfo)
		{
			var propertyValue = (IDbObject) propertyInfo.GetValue(o, null);
			if (propertyValue != null)
			{
				var itemId = propertyValue.Id;
				if (persistentRelation.Contains(itemId))
				{
					persistentRelation.Remove(propertyValue.Id);
					if (!objectGraph.ContainsKey(propertyValue))
					{
						Update(propertyValue, connection, objectGraph);	
					}
				}
				else
				{
					if (itemId == 0)
					{
						Insert(propertyValue, connection, objectGraph);
					}
					else if (!objectGraph.ContainsKey(propertyValue))
					{
						Update(propertyValue, connection, objectGraph);
					}
					command.CommandText = "UPDATE " + mappingTable + " SET `" + relation.OriginalKey + "` = " + o.Id + " WHERE Id = " + propertyValue.Id;
					command.ExecuteNonQuery();
				}
			}
			if (persistentRelation.Count > 0)
			{
				command.CommandText = "UPDATE " + mappingTable + " SET `" + relation.OriginalKey + "` = NULL WHERE Id = @id";
				command.Prepare();
				command.Parameters.Add(new MySqlParameter("@Id", persistentRelation[0]));
				command.ExecuteNonQuery();
				for (var i = 1; i < persistentRelation.Count; i++)
				{
					command.Parameters["@Id"].Value = persistentRelation[i];
					command.ExecuteNonQuery();
				}
			}		
		}
开发者ID:epdumitru,项目名称:mysqlib,代码行数:41,代码来源:ReflectionDbFunctionHelper.cs

示例5: UpdateNNRelation

		private void UpdateNNRelation(IDictionary<IDbObject, long> objectGraph, IDbObject o, DbConnection connection, RelationInfo relation, DbCommand command, string mappingTable, List<long> persistentRelation, PropertyInfo propertyInfo)
		{
			var listCurrentPropertyValue = (IList)propertyInfo.GetValue(o, null);
			if (listCurrentPropertyValue != null)
			{
				for (var i = 0; i < listCurrentPropertyValue.Count; i++)
				{
					var item = (IDbObject)listCurrentPropertyValue[i];
					if (item == null) continue;
					var itemId = item.Id;
					if (persistentRelation.Contains(itemId))
					{
						if (!objectGraph.ContainsKey(item))
						{
							Update(item, connection, objectGraph);
						}
						persistentRelation.Remove(itemId);
					}
					else
					{
						if (itemId == 0)
						{
							Insert(item, connection, objectGraph);
						}
						else if (!objectGraph.ContainsKey(item))
						{
							Update(item, connection, objectGraph);
						}
						try
						{
							command.CommandText = "INSERT INTO " + mappingTable + "  ( `" + relation.OriginalKey + "`, `" + relation.PartnerKey + "`) VALUES (" + o.Id + ", " + item.Id + ")";
							command.ExecuteNonQuery();
						}
						catch
						{
						}
						
					}
				}
			}
			if (persistentRelation.Count > 0)
			{
				command.CommandText = "DELETE FROM " + mappingTable + " WHERE `" + relation.OriginalKey + "` = " + o.Id + " AND `" + relation.PartnerKey + "` = @partnerId";
				command.Prepare();
				command.Parameters.Add(new MySqlParameter("@partnerId", persistentRelation[0]));
				command.ExecuteNonQuery();
				for (var i = 1; i < persistentRelation.Count; i++)
				{
					command.Parameters["@partnerId"].Value = persistentRelation[i];
					command.ExecuteNonQuery();
				}
			}
		}
开发者ID:epdumitru,项目名称:mysqlib,代码行数:53,代码来源:ReflectionDbFunctionHelper.cs

示例6: ExecuteNonQuery

 public int ExecuteNonQuery(DbCommand command)
 {
     int result = 0;
     doSynchronized(() => {
         DbConnection conn = GetOpenConnection();
         MySqlCommand mysqlCommand = (MySqlCommand)command;
         command.Connection = conn;
         int executeResult = command.ExecuteNonQuery();
         if ((int)mysqlCommand.LastInsertedId > 0) {
             result= (int)mysqlCommand.LastInsertedId;
         } else {
             result = executeResult;
         }
     });
     return result;
 }
开发者ID:Ethon,项目名称:mcflurry_simulator,代码行数:16,代码来源:MYSQLDatabase.cs

示例7: ExecuteNonQuery

 public override int ExecuteNonQuery(DbCommand command)
 {
     if (_Connection.State != System.Data.ConnectionState.Open) _Connection.Open();
     command.Connection = _Connection;
     command.Transaction = _Transaction;
     return command.ExecuteNonQuery();
 }
开发者ID:danielgindi,项目名称:dg.Sql,代码行数:7,代码来源:MySqlConnector.cs

示例8: LoadLocalFileIntoTable

        /// <summary>
        /// Loads the contents of a local file into the given table.
        /// </summary>
        /// <param name="tablename">The name of the table to load the data into.</param>
        /// <param name="filename">The name of the local file to load the data from.</param>
        /// <param name="command">The MySQL command to perform the update with.</param>
        /// <param name="columns">The comma separated list of columns to load the data into.</param>
        private void LoadLocalFileIntoTable(string tablename, string filename, DbCommand command, string columns)
        {
            Console.WriteLine($"Truncating {tablename}");
            command.CommandText = $"TRUNCATE {tablename}";
            command.ExecuteNonQuery();

            Console.WriteLine($"Loading {tablename} table into database.");

            if (command is MySqlCommand)
            {
                command.CommandText = $"LOAD DATA LOCAL INFILE '{filename}' INTO TABLE {tablename} LINES TERMINATED BY '\r\n'";
            }
            else if (command is NpgsqlCommand)
            {
                string winFilename = new FileInfo(filename).FullName;
                command.CommandText = $"COPY {tablename} ({columns}) FROM '{winFilename}' (DELIMITER '\t')";
            }
            else
            {
                throw new ArgumentException();
            }

            command.ExecuteNonQuery();
        }
开发者ID:marshl,项目名称:MtgJsonParser,代码行数:31,代码来源:Parser.cs

示例9: UpdateTableWithNewCardIDs

 /// <summary>
 /// Updates the usercard IDs in the given table name with new IDs, using the oldtonewcards table.
 /// </summary>
 /// <param name="tablename">The table to update.</param>
 /// <param name="command">The command to update the table with.</param>
 private void UpdateTableWithNewCardIDs(string tablename, DbCommand command)
 {
     command.CommandText = $"UPDATE {tablename} t SET cardid = ( SELECT o.newcardid FROM oldtonewcards o WHERE o.oldcardid = t.cardid )";
     command.ExecuteNonQuery();
 }
开发者ID:marshl,项目名称:MtgJsonParser,代码行数:10,代码来源:Parser.cs

示例10: RefreshDelverFromMagicDb

        /// <summary>
        /// Truncates existing user tables, and loads data from the old database.
        /// </summary>
        /// <param name="command">The sql command to use.</param>
        private void RefreshDelverFromMagicDb(DbCommand command)
        {
            Console.Write("Refreshing data set from magic_db database.");

            command.CommandText = @"
                INSERT INTO historicalcards
                (SELECT cardid id, name FROM magic_db.oracle)";
            command.ExecuteNonQuery();

            command.CommandText = "TRUNCATE usercards";
            command.ExecuteNonQuery();

            command.CommandText = "INSERT INTO usercards ( SELECT * FROM magic_db.usercards)";
            command.ExecuteNonQuery();

            command.CommandText = "TRUNCATE usercardchanges";
            command.ExecuteNonQuery();

            command.CommandText = "INSERT INTO usercardchanges ( SELECT * FROM magic_db.usercardlog)";
            command.ExecuteNonQuery();

            command.CommandText = "TRUNCATE taglinks";
            command.ExecuteNonQuery();

            command.CommandText = "INSERT INTO taglinks ( SELECT * FROM magic_db.taglinks)";
            command.ExecuteNonQuery();

            command.CommandText = "TRUNCATE deckcards";
            command.ExecuteNonQuery();

            command.CommandText = "INSERT INTO deckcards ( SELECT * FROM magic_db.deckcards)";
            command.ExecuteNonQuery();

            Console.WriteLine("Done");
        }
开发者ID:marshl,项目名称:MtgJsonParser,代码行数:39,代码来源:Parser.cs

示例11: UpdateDatabaseWithCommand

        /// <summary>
        /// Updates a database using the given command.
        /// </summary>
        /// <param name="command">The command to update the database (includes which database to update)</param>
        /// <param name="refreshFromOldData">Whether to update the database with old data.</param>
        private void UpdateDatabaseWithCommand(DbCommand command, bool refreshFromOldData)
        {
            if (!refreshFromOldData)
            {
                command.CommandText = "TRUNCATE historicalcards";
                command.ExecuteNonQuery();

                command.CommandText = @"
                       INSERT INTO historicalcards
                       (SELECT id, name FROM cards)";
                command.ExecuteNonQuery();
            }

            Console.Write("Loading files into database... ");

            this.LoadLocalFileIntoTable("cards", "temp/cards", command, "id,name,cost,cmc,colour,colouridentity,numcolours,type,subtype,power,numpower,toughness,numtoughness,loyalty,rules");
            this.LoadLocalFileIntoTable("cardsets", "temp/cardsets", command, "cardid,setcode,multiverseid,artist,flavourtext,rarity,collectornum");
            this.LoadLocalFileIntoTable("blocks", "temp/blocks", command, "id,name");
            this.LoadLocalFileIntoTable("sets", "temp/sets", command, "id,code,name,blockid,release_date");
            this.LoadLocalFileIntoTable("types", "temp/types", command, "id,name");
            this.LoadLocalFileIntoTable("subtypes", "temp/subtypes", command, "id,name");
            this.LoadLocalFileIntoTable("cardlinks", "temp/links", command, "cardid_from,cardid_to,link_type");

            Console.WriteLine("Done");

            Console.Write("Creating old-to-new-card-id table... ");

            command.CommandText = "TRUNCATE oldtonewcards";
            command.ExecuteNonQuery();

            command.CommandText = @"
            INSERT INTO oldtonewcards(
                SELECT hc.id, c.id
                FROM cards c
                JOIN historicalcards hc
                ON hc.name = c.name
            )";
            command.ExecuteNonQuery();

            Console.WriteLine("Done");

            Console.Write("Updating old card IDs with new values... ");

            this.UpdateTableWithNewCardIDs("usercards", command);
            this.UpdateTableWithNewCardIDs("usercardchanges", command);
            this.UpdateTableWithNewCardIDs("taglinks", command);
            this.UpdateTableWithNewCardIDs("deckcards", command);

            Console.WriteLine("Done");
        }
开发者ID:marshl,项目名称:MtgJsonParser,代码行数:55,代码来源:Parser.cs

示例12: Update

        //Update statement
        public void Update(DbCommand update_query)
        {
            try
            {
                //Open connection
                if (this.OpenConnection() != null)
                {

                    //Assign the query using CommandText
                    update_query.Connection = connection;

                    update_query.Prepare();

                    //Execute query
                    update_query.ExecuteNonQuery();

                    //close connection
                    this.CloseConnection();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
开发者ID:nkasozi,项目名称:Nkujukira,代码行数:26,代码来源:MySQLDataBaseHandler.cs

示例13: Insert

        //Insert statement
        public void Insert(DbCommand insert_query)
        {
            //open connection
            if (this.OpenConnection() != null)
            {

                insert_query.Connection = connection;
                insert_query.Prepare();

                //Execute command
                insert_query.ExecuteNonQuery();

                //close connection
                this.CloseConnection();
            }
        }
开发者ID:nkasozi,项目名称:Nkujukira,代码行数:17,代码来源:MySQLDataBaseHandler.cs

示例14: Delete

 //Delete statement
 public void Delete(DbCommand delete_query)
 {
     try
     {
         if (this.OpenConnection() != null)
         {
             delete_query.Connection = connection;
             delete_query.Prepare();
             delete_query.ExecuteNonQuery();
             this.CloseConnection();
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
     }
 }
开发者ID:nkasozi,项目名称:Nkujukira,代码行数:18,代码来源:MySQLDataBaseHandler.cs


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