Basic SQL access


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. private Dictionary<string, int> Data
  2. {
  3. get
  4. {
  5. Dictionary<string, int> data = new Dictionary<string, int>();
  6.  
  7. using (SqlConnection conn = new SqlConnection(connectionString))
  8. {
  9. SqlDataReader rdr = null;
  10.  
  11. conn.Open();
  12.  
  13. string query = "";
  14.  
  15. SqlCommand cmd = new SqlCommand(query, conn);
  16.  
  17. using (rdr = cmd.ExecuteReader())
  18. {
  19. while (rdr.Read())
  20. {
  21. data.Add(((DateTime)rdr["date"]).ToString("MM-yyyy"), (int)rdr["visits"]);
  22. }
  23. }
  24. }
  25. return data;
  26. }
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.