本文整理汇总了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();
}
}
}
示例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();
}
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
}