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


C# DbCommand.Prepare方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

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