public ICollection<Experiment> GetExperiments() { using (var db = new AP439DBDataContext()) { // Get the full list of products. // Create a second collection with matching products. var exs = from ex in db.Experiments select ex; return new ObservableCollection<Experiment>(exs.ToList()); //foreach (var ex in exs) //{ // Console.WriteLine(ex); //} } //List<Experiment> exs = new List<Experiment>(); //using (SqlConnection con = new SqlConnection(connectionString)) //{ // con.Open(); // using (SqlCommand command = new SqlCommand("SELECT * FROM Experiments", con)) // { // SqlDataReader reader = command.ExecuteReader(); // while (reader.Read()) // { // string weight = reader.GetString(0); // Weight int // string name = reader.GetString(1); // Name string // string breed = reader.GetString(2); // Breed string // exs.Add(new Experiment() { Date = weight, ExID = name, Name = breed }); // } // } //} //foreach (Experiment ex in exs) //{ // Console.WriteLine("date = {0} exID = {1} name = {2}", ex.Date, ex.ExID, ex.Name); //} }
//public void TryCreateTable() //{ // using (SqlConnection con = new SqlConnection(connectionString)) // { // con.Open(); // try // { // using (SqlCommand command = new SqlCommand( // "CREATE TABLE Experiments (Date TEXT, ExID TEXT, Name TEXT)", con)) // { // command.ExecuteNonQuery(); // } // } // catch // { // Console.WriteLine("Table not created."); // //throw new Exception(); // } // } //} public void InsertLog(DateTime date, int exID, string name) { var ex = new Experiment(); ex.Date = date; ex.ExID = exID; ex.Username = name; using (var db = new AP439DBDataContext()) { db.Experiments.InsertOnSubmit(ex); db.SubmitChanges(); } //using (SqlConnection con = new SqlConnection(connectionString)) //{ // con.Open(); // DataTable t = con.GetSchema(); // try // { // using (SqlCommand command = new SqlCommand( // "INSERT INTO Experiments(Date,ExID,Name) VALUES(@Date, @ExID, @Name)", con)) // { // command.Parameters.Add(new SqlParameter("Date", date)); // command.Parameters.Add(new SqlParameter("ExID", exID)); // command.Parameters.Add(new SqlParameter("Name", name)); // command.ExecuteNonQuery(); // } // } // catch(Exception e) // { // Console.WriteLine(e); // Console.WriteLine("Can not insert."); // //throw new Exception(); // } //} }