日期:2014-05-17 浏览次数:20897 次
public IEnumerable<T> ExecuteQuery<T>(string sql, DbParameter[] ps, Func<DbDataReader, T> proc)
{
var str = "Data Source=.;Initial Catalog=TestDB;Integrated Security=True";
using (DbConnection con = new SqlConnection(str))
{
con.Open();
var cmd = con.CreateCommand();
cmd.CommandText = sql;
if (ps != null)
cmd.Parameters.AddRange(ps);
var reader = cmd.ExecuteReader();
while (reader.Read())
yield return proc(reader);
}
}