tags:

views:

588

answers:

2

Looking for an example in linq about how to insert a row of a gridview into datacontext.

+1  A: 

First - you'd need a typed object. This will obviously be easier if your gridview is already data-bound. You can use InsertOnSubmit (new record) or Attach (update existing) to associate a record with a data-context. Alternatively, bind to object you got from the data-context in the first place. One simple way of doing that is via GetNewBindingList (how well this works depends on the scenario).

If that doesn't help, perhaps explain more about your scenario?

Marc Gravell
+1  A: 
using (WebShop.DDFAdminwebshopDataContext db = new WebShop.DDFAdminwebshopDataContext())

        {
            var productstags = from productstag in db.sk_productstags where productstag.productid == _productid
                               && productstag.tagid == _tagid select productstag;


            if (productstags.Count() == 0) {

                WebShop.DDFAdmin.sk_productstags entProductTag = new WebShop.DDFAdmin.sk_productstags();
                entProductTag.productid = _productid;
                entProductTag.tagid = _tagid;

                db.sk_productstags.InsertOnSubmit(entProductTag);
                db.SubmitChanges();
            }

        }
balint