Tom Knowlton
asked on
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.Eleme ntAt(0).Fi eld<string >("usernam e") + " 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)
DataSet ds = DataHelper.ReturnDataSet("
DataTable dt = ds.Tables[0];
var query =
from o in dt.AsEnumerable()
where o.Field<string>("email") == email
&& o.Field<string>("password"
select o;
int count = query.Count();
if (count == 1)
{
Response.Write(query.Eleme
}
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)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>("emai l", "test@mail.com");
After that you can insert/update data from your DataSet to database via DataAdapter.
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>("emai
After that you can insert/update data from your DataSet to database via DataAdapter.
ASKER
Uh.... okay.