• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2617
  • Last Modified:

LINQ to DataSet - perform an insert or update - in C# syntax

Trying to learn LINQ:

DataSet ds = DataHelper.ReturnDataSet("select * from llpp_users");

            DataTable dt = ds.Tables[0];

            var query =
                    from o in dt.AsEnumerable()
                    where o.Field<string>("email") == email
                    && o.Field<string>("password") == password
                    select o;

            int count = query.Count();

            if (count == 1)
            {
                Response.Write(query.ElementAt(0).Field<string>("username") + " is signed in.");
            }


This seems to work........but how do I do an INSERT or an UPDATE using LINQ syntax  (notice that I am using LINQ to DataSet)
0
Tom Knowlton
Asked:
Tom Knowlton
  • 2
1 Solution
 
lazyberezovskyCommented:
Well, I think you should not do INSERT or UPDATE using language-integrated QUERY (LINQ). Purpose of LINQ to DataSet is to simplify querying data from DataSets, because original DataSets objects provided very poor functionality with Select method.
0
 
Tom KnowltonWeb developerAuthor Commented:
Oh....

Uh....  okay.
0
 
lazyberezovskyCommented:
Hi, knowlton

Sorry, I was not complete about this. You can change data in your DataTable via calling SetField method.
E.g:

foreach (var row in query)
    row.SetField<string>("email", "test@mail.com");

After that you can insert/update data from your DataSet to database via DataAdapter.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now