How do I read data from a database using LINQ to SQL in VB using an IQueryable?

I am fairly new to visual basic and know only a little about LINQ and SQL. I know how to select items from an array with LINQ, but what I can't figure out how to do is access a database using an IQueryable. I connected the database to my project, added two classes from the database to the "LINQ to SQL" .dbml file and saved it. In my programming assignment, I am not supposed to create a data source (table thing) to display the data, but update my own interface manually. In order to do it, I was told to instantiate this:

Private dogs As System.Linq.IQueryable(Of Dog)

(Dog is a class that I added to my .dbml file from the database file)

Also, I am told it involves using a method

.AsEnumerable.ElementAt(index As Integer)

And somehow I am supposed to load database data from/using this. Help please if you can. I got screwed over by my professors as our online assignment program was down the whole thanksgiving break so I'm here doing this at the last minute. Thanks.


You have to make an instance of your data context class (which has the same name as your dbml + "DataContext"). Let's say it is AnimalsDataContext:

using (var context = new AnimalsDataContext())
    var dogs = context.Dogs;

Need Your Help

Web service that parses XML data for Windows 8 app

c# xml web-services soap windows-8

I am trying to create a windows 8 app that will allow my users to create records in gridview and when prompted will allow them to send them to a database and then allow them to modify/delete them. ...

C sha1 implementation not working on Unix

c windows unix sha

I'm using this implementation of SHA1 in C. Works fine on Windows but it does not output correct hashes on Unix (tried it on Ubuntu and Mac OS 10.8). Furthermore, on Ubuntu it outputs different has...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.