I try to add a record to SQLServer db table using LINQ to SQL in my WPF app, but always get an error regarding missing directive. Usually intellisense gives a hint on such issue, but not this time. Here my code with all directives:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
...
...
DateTime newdate = new DateTime(2010, 2, 1);
TimeSpan newtime = new TimeSpan(12, 00, 00);
MyfirstdbDataContext context = new MyfirstdbDataContext();
Meeting meeting = new Meeting();
meeting.MeetID = "01.02.10_12:00";
meeting.Date = newdate;
meeting.Time = newtime;
context.Meetings.Add(meeting); // Here I get the debugger error
context.SubmitChanges();
And I get this error:
System.Data.Linq.Table' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Data.Linq.Table' could be found (are you missing a using directive or an assembly reference?)
Please, what could be wrong with my code?
The correct syntax is:
context.Meetings.InsertOnSubmit(meeting);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With