public static DataTable ExecuteCmdTable(System.Data.SQLite.SQLiteCommand cmd) { System.Data.ConnectionState origSate = cmd.Connection.State; if (cmd.Connection.State == ConnectionState.Closed) { cmd.Connection.Open(); } DataTable dt; System.Data.SQLite.SQLiteDataReader dr; dt = new DataTable(); dr = cmd.ExecuteReader(); dt.Load(dr); dr.Close(); dr = null; if (origSate == ConnectionState.Closed) { cmd.Connection.Close(); } return dt; }
public System.Data.SqlClient.SqlDataReader ejecutaSP(System.Data.SqlClient.SqlCommand comando) { comando.Connection = con; comando.CommandType = CommandType.StoredProcedure; System.Data.SqlClient.SqlDataReader datos = comando.ExecuteReader(); return datos; }
public System.Data.Common.DbDataReader Select(System.Data.Common.DbCommand command) { command.Prepare(); DbDataReader sqlReader = command.ExecuteReader(); return sqlReader; }
private IEnumerable<string> SelectFolderEntries(System.Data.IDbCommand cmd, string prefix, string table) { if (!string.IsNullOrEmpty(prefix)) prefix = Duplicati.Library.Utility.Utility.AppendDirSeparator(prefix); var ppl = prefix.Length; using(var rd = cmd.ExecuteReader(string.Format(@"SELECT DISTINCT ""Path"" FROM ""{0}"" ", table))) while (rd.Read()) { var s = rd.GetString(0); if (!s.StartsWith(prefix)) continue; s = s.Substring(ppl); var ix = s.IndexOf(System.IO.Path.DirectorySeparatorChar); if (ix > 0 && ix != s.Length - 1) s = s.Substring(0, ix + 1); yield return prefix + s; } }
public static System.Data.SqlServerCe.SqlCeDataReader ExecuteReader(System.Data.SqlServerCe.SqlCeCommand command) { bool retry = false; try { return command.ExecuteReader(); } catch (System.Data.SqlServerCe.SqlCeException ex) { if (ex.NativeError == 0) { retry = true; } else { throw; } } if (retry) { command.Connection.Close(); command.Connection.Open(); return command.ExecuteReader(); } else return null; }
private List<Dictionary<string, object>> DumpTable(System.Data.IDbCommand cmd, string tablename, string pagingfield, string offset_str, string pagesize_str) { var result = new List<Dictionary<string, object>>(); long pagesize; if (!long.TryParse(pagesize_str, out pagesize)) pagesize = 100; pagesize = Math.Max(10, Math.Min(500, pagesize)); cmd.CommandText = "SELECT * FROM \"" + tablename + "\""; long offset = 0; if (!string.IsNullOrWhiteSpace(offset_str) && long.TryParse(offset_str, out offset) && !string.IsNullOrEmpty(pagingfield)) { var p = cmd.CreateParameter(); p.Value = offset; cmd.Parameters.Add(p); cmd.CommandText += " WHERE \"" + pagingfield + "\" < ?"; } if (!string.IsNullOrEmpty(pagingfield)) cmd.CommandText += " ORDER BY \"" + pagingfield + "\" DESC"; cmd.CommandText += " LIMIT " + pagesize.ToString(); using(var rd = cmd.ExecuteReader()) { var names = new List<string>(); for(var i = 0; i < rd.FieldCount; i++) names.Add(rd.GetName(i)); while (rd.Read()) { var dict = new Dictionary<string, object>(); for(int i = 0; i < names.Count; i++) dict[names[i]] = rd.GetValue(i); result.Add(dict); } } return result; }
public class LogData : IRESTMethodGET, IRESTMethodDocumented
public static System.Data.IDataReader ExecuteReader(System.Data.IDbCommand cmd) { System.Data.IDataReader idr = null; lock (cmd) { System.Data.IDbConnection idbc = GetConnection(); cmd.Connection = idbc; if (cmd.Connection.State != System.Data.ConnectionState.Open) cmd.Connection.Open(); try { // http://www.mysqlab.net/knowledge/kb/detail/topic/c%23/id/4917 idr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection | System.Data.CommandBehavior.SequentialAccess); } catch (System.Data.Common.DbException ex) { if (Log(ex, cmd)) throw; } } // End Lock cmd return idr; }
public void Read() { string strQuerySelect = "SELECT * FROM VEICULO"; SqlCommand cmdRead = new SqlCommand(strQuerySelect, ); SqlDataReader rd = cmdRead.ExecuteReader(); }