I'm trying to do dml operations on Linq by ExecuteQuery() and ExecuteCommand(). The error that occurred is after execution it doesn't affects the record in database.
For eg: To insert a new record to table in database, I used ExecuteCommand().
After the error occurred i coded with Submitchanges() but there is no result of what i expect.
A Sample code for inserting data to a table:
using(StudentsDbDataContext StudentContext = new StudentsDbDataContext())
{
int r = StudentContext.ExecuteCommand("insert into tblStudents values ({0},{1},{2})", firstname, lastname, gender);
if (r > 0) {
Console.WriteLine("{0} row added.", r);
Console.ReadKey();
}
}
What I have tried:
using(StudentsDbDataContext StudentContext = new StudentsDbDataContext())
{
int r = StudentContext.ExecuteCommand("insert into tblStudents values ({0},{1},{2})", firstname, lastname, gender);
StudentContext.SubmitChanges();
if (r > 0) {
Console.WriteLine("{0} row added.", r);
Console.ReadKey();
}
}
How to solve this?