本文整理汇总了C#中ConnectionFactory.CreateCommand方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionFactory.CreateCommand方法的具体用法?C# ConnectionFactory.CreateCommand怎么用?C# ConnectionFactory.CreateCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionFactory
的用法示例。
在下文中一共展示了ConnectionFactory.CreateCommand方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public IDbCommand Build(string connectionString, string query, IEnumerable<IQueryParameter> parameters, IEnumerable<IQueryTemplateVariable> variables)
{
var conn = new ConnectionFactory().Get(connectionString);
var cmd = conn.CreateCommand();
if (variables != null && variables.Count() > 0)
query = ApplyVariablesToTemplate(query, variables);
cmd.CommandText = query;
if (parameters!=null && parameters.Count()>0)
{
foreach (var p in parameters)
{
var param = cmd.CreateParameter();
if (cmd is AdomdCommand && p.Name.StartsWith("@"))
p.Name = p.Name.Substring(1, p.Name.Length - 1);
if (cmd is SqlCommand && !p.Name.StartsWith("@") && char.IsLetter(p.Name[0]))
p.Name = "@" + p.Name;
param.ParameterName = p.Name;
var stringWithoutSpecialChars = p.StringValue.Replace("\n", "").Replace("\t", "").Replace("\n", "").Trim();
param.Value = stringWithoutSpecialChars;
var dbType = new DbTypeBuilder().Build(p.SqlType);
if (dbType != null)
{
param.Direction = ParameterDirection.Input;
param.DbType = dbType.Value;
param.Size = dbType.Size;
param.Precision = dbType.Precision;
}
cmd.Parameters.Add(param);
}
}
return cmd;
}
示例2: BuildCommand
protected IDbCommand BuildCommand(string query, string connectionString)
{
var conn = new ConnectionFactory().Get(connectionString);
var cmd = conn.CreateCommand();
cmd.CommandText = query;
return cmd;
}