Groups > Asp .Net > Data Access and ObjectDataSource Control > Re: A array contains Id's How to get the rows with Linq




A array contains Id's How to get the rows with Linq

A array contains Id's How to get the rows with Linq
Tue, 1 Apr 2008 03:33:39 +0000
I have a Array With Id' numbers.

How can I get the rows  from database contaning the Id's from array??
Post Reply
Re: A array contains Id's How to get the rows with Linq
Tue, 1 Apr 2008 19:20:12 +0000
Here's a small example for you: 

ASPX 

<asp:gridview id="GridView1" runat="server">
</asp:gridview>

CODE-BEHIND 

using System;
using System.Linq;
using LinqToSql;

public partial class Posts_DataAccess_DataAccess_1241173 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!this.IsPostBack)
		{
			int[] ids = new int[] { 1, 3, 5, 7, 9 };

			var products = from p in DBContext.Northwind.Products
						   where ids.Contains(p.ProductID)
						   select p;

			GridView1.DataSource = products;
			GridView1.DataBind();
		}
    }
}
Post Reply
Re: A array contains Id's How to get the rows with Linq
Wed, 2 Apr 2008 00:05:06 +0000
Thanks it worked...
Post Reply
Re: A array contains Id's How to get the rows with Linq
Wed, 2 Apr 2008 07:14:25 +0000
Wow that's one smart little girl :)

 Just what I needed too thanks
Post Reply
Re: A array contains Id's How to get the rows with Linq
Wed, 2 Apr 2008 11:37:49 +0000
Done with work .. check out this
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact