Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var conn = new SqlConnection(ConnString);
- conn.Open();
- var data = new Dictionary<string, List<object>>();
- foreach (var h in hours)
- {
- data += SqlUniversal.GetAllData(query,
- new[] {
- //some parameters
- },
- conn);
- }
- //Here is the method, above is how I call it.
- public static Dictionary<string, List<object>> GetAllData(string command, SqlParameter[] pars, SqlConnection conn)
- {
- if (conn == null)
- {
- conn = new SqlConnection(ConnString);
- conn.Open();
- }
- var res = new Dictionary<string, List<object>>();
- using (conn)
- {
- using (var cmd = new SqlCommand(command, conn))
- {
- cmd.Parameters.AddRange(pars);
- using (var reader = cmd.ExecuteReader())
- {
- while (reader.Read())
- for (var i = 0; i < reader.VisibleFieldCount; i++)
- {
- if (reader.GetValue(i) == DBNull.Value)
- continue;
- var name = reader.GetName(i);
- if (res.ContainsKey(name))
- res[name].Add(reader.GetValue(i));
- else
- res.Add(name, new List<object> {reader.GetValue(i)});
- }
- return res;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment