Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with adding record using LINQ to SQL

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?

like image 214
rem Avatar asked Dec 07 '22 04:12

rem


1 Answers

The correct syntax is:

context.Meetings.InsertOnSubmit(meeting);
like image 133
Aviad P. Avatar answered Dec 10 '22 03:12

Aviad P.