.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

linq - delete dropdownlist

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :ASP.Net
My code:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"DataSourceID="LinqDataSource1" DataTextField="UserId" DataValueField="UserId"></asp:DropDownList>BurnbetDataDataContext db = new BurnbetDataDataContext();        var selectedID = (DropDownList1.SelectedValue);        tbl_Payment toDelete = db.tbl_Payments.Single(p => p.UserId == selectedID);        db.tbl_Payments.DeleteOnSubmit(toDelete);        db.SubmitChanges();Error:System.InvalidOperationException was unhandled by user code  Message=Sequence contains more than one element  Source=System.Data.Linq  StackTrace:       at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)       at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)       at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IPr

View Complete Post

More Related Resource Links

delete a row in datatable using linq to dataset

hihow can i delete a row in datatable using linq to dataset?I have a dataset in my project, need to delete some rows filtered by IDhow can i do?

LINQ - Can't perform Create, Update or Delete operations on because it has no primary key.

Hi, not sure if I'm posting this thread in the right section. anyway, I''m trying to do the update/insert/delete using LINQ but the underlying table does not a primary key. The table consists of composite ket (e.g. fieldA & FieldB make a primary key). At the moment, I have LINQ complaning about not having a single primary key (not sure what LINQ does it - not making any sense at all). did anyone ever come across this issue and rectified it?  thanks

Cascading DropDownList with LINQ

My application includes a gridview control with and Edit mode which allows users to do selections using cascading dropdownlist. My code is based on tutorial by Brian Orrell (link below). I am able to statically populate the dropdownlist but in my case I need to populate it dynamically based on a previous selection of a dropdownlist, I would like to do it programatically so I can manipulate data. I Could not find any code samples which show how to do it progamatically if anybody knows of a site with such example please post a link   http://borrell.parivedasolutions.com/2008/01/objectdatasource-linq-paging-sorting.html

Is the delete records LINQ correct ?

I hope to delete all records in DBPrograms, is the following code correct?               DBContext db = DBContext(PublicDBPar.ConnectionString);            db.DBPrograms.DeleteAllOnSubmit(db.DBPrograms);            db.SubmitChanges();

linq - delete two tables not work

BurnbetDataContext db = new BurnbetDataContext(); var q = (from c in db.GetTable<tbl_Payment>() where c.UserId == "fc44c835-8e80-45ee-af84-68339a09c053" select c).Single<tbl_Payment>(); db.GetTable<tbl_Payment>().DeleteOnSubmit(q); db.SubmitChanges(); In App_Code I BurnbetDataContext.I have two tables and tbl_PaymentDetails tbl_PaymentAssociation is:Parent Child Class -->>> UserId UserId ClassData in Table tbl_PaymentDetails (child) does not delete.      

MS Linq To SQL Samples - Insert/Update/Delete

Hi, I'm stumbling along trying my hand at Linq to SQL and have come across this code below that was provided by MS.http://msdn.microsoft.com/en-us/vbasic/bb737928.aspxThe problem is there is no ".add" method for Categories to chose in the statement db2.Categories.add(newCategory)I've seen similar videos here on ASP .NET that uses code very much like the example below, but I am unable to run this example connected to a Northwind SQL database using Web Developer 2010 Express. This is the One-to-Many example listed under Linq To SQL Samples - Insert/Update/Delete. Thanks for any help! Shawn Dim db2 = New DataClassesDataContext Dim ds = New DataLoadOptions() ds.LoadWith(Of Category)(Function(p) p.Products) db2.LoadOptions = ds Dim newCategory = New Category With {.CategoryName = "Widgets", _ .Description = "Widgets are the customer-facing analogues " & _ "to sprockets and cogs.", _ .Picture = Nothing} Dim newProduct = New Product With {.ProductName = "Blue Widget", _ .UnitPrice = 34.56#, _ .Category = newCategory, _

delete node based on criteria - linq to xml


I'm trying to delete an element based on its inner text but seem to not quite have it...

I have an xml doc like this:
<department name="Claims">
    <MyElement>Big Test</MyElement>


My linq to xml is:

XDocument ldoc = XDocument.Load(Server.MapPath("/XML/Settings.xml"));

doc.Elements("department").Where(s => s.Element("keywords").Value == "phone").Remove();



When I click my link button the element <keywords>phone</keywords> is never deleted.

Any idea what i'm doing wrong?




How to update and delete with Linq?



I use Linq to Entities and want to update and delete data. I know the ID of the object / record.

How can  update and delete without first selecting the complete object (asuming that this is better for performance)?


Linq to entities: Always select before delete and update?



With linq to entities, how can I delete and update data inside a database without first selecting the complete entity at first?
The idea behind this is to improve performance.


dropdownlist LINQ to SQL


Hi there,

I'm trying to populate a dropdonlist after a postback in a footer of a gridview, I've been copyng so many examples where they say to do it this way but  I keep gettin' exception when databinding why?

private void FillGrupos(int Category)
            Sports.Data_Access.MyDataContext db = new Sports.Data_Access.MyDataContext();

            var groups = from gr in db.tblGrupo
                         where gr.CatId == Category
                         orderby gr.Group descending
                         select new
                             GroupId = gr.GroupId,
                             Group = gr.Group,

            DropDownList ddl = (DropDownList) GridView1.FooterRow.FindControl("DropDownListFooterGroup");
            ddl.DataSource= groups;
            ddl.DataTextField = "Group";
            ddl.DataValueField = "GroupId";


LINQ how to get data from dropdownlist in label1


            var dnevnice = from p in db.tbl_dnevnices
                         select p.Drzava;

            ddlDnevnice.DataSource = dnevnice;

I have label1.text.

Example: ID

How to display data according to the selected data in DropDownList?

Help: populate Html.DropDownList from table data? [Linq to SQL model]


I have two tables, Users and Roles.  The roles table is a reference table for the different roles of my site (RoleId and RoleName columns). The Users table contains profile data for each user, including a RoleId column that is FK'd back to the Roles table [RoleId].

Both tables are in a Linq to SQL model.

I have an edit page created which lists all the profile values of a user.  The edit page inherits the User model.  One of the editable values is the RoleId field.  I want to set this up to be a drop-down list that contains items labeled using the RoleName column of the Roles table, and matched with values of RoleId.

How can I achieve this?

linq delete


        GridViewRow row = (GridViewRow)((LinkButton)sender).NamingContainer;
        int ID = Convert.ToInt32(ViewRelacije.DataKeys[row.RowIndex].Value);

        var deleteQ = db.tbl_relacijes.FirstOrDefault(del => del.ID == ID);


This code works.
But I have trouble refreshing.
It would be less code, would like to embed a "select" to see the data.
What do I do?

I think something like this:

GridViewRow row = (GridViewRow)((LinkButton)sender).NamingContainer;
        int ID = Convert.ToInt32(ViewRelacije.DataKeys[row.RowIndex].Value);

GridViewRow row = (GridViewRow)((LinkButton)sender).NamingContainer;
        int ID = Convert.ToInt32(ViewRelacije.DataKeys[row.RowIndex].Value);

        var deleteQ = db.tbl_relacijes.FirstOrDefault(del => del.ID == ID);



How to get two data in dropdownlist with Linq


var customers = from c in db.tbl_relacije_sifrants
                        select new

        ddlRelacijeSifrant.DataSource = customers;
        ddlRelacijeSifrant.DataTextField = "Relacija";
        ddlRelacijeSifrant.DataValueField = "ID";

I need Two Pieces of data and the DropDownList.

Relationship + SifraId = DropDownList

What do I do?


Playing with Linq grouping: GroupByMany?

One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier.

LINQ : Implementing IN and NOT IN

I got tried of typing

var result = from s in source
where items.Contains(s)
select s;and so I implemented the IN and NOT IN methods as extension methods:

101 LINQ Samples Tutorials

101 LINQ Example with sample code snippets....This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend