none
Not getting any records back when making a linq query against my northwind.xsd RRS feed

  • Question

  • I added a dataset to my app called northwind.xsd and connected it to a nwind.mdb file.

     

    In the database explorer I can view all of my tables and the data in them. I dragged several tables from the explorer to the Northwind.xsd, it shows them properly, including relations.

     

    In my vb code I am trying to make a simple query against the customer table which executes without error but returns no records.

     

    Here is my code

     

    Code Snippet

    Dim db As New Northwind()

    Dim matchingCustomers = From cust In db.Customers Where cust.Country Like "*" Select cust

    For Each customer In matchingCustomers

    Console.WriteLine("> {0,33} / {1,30} / {2,4}", _

    customer.CompanyName, customer.ContactName, customer.Country)

    Next

    Console.WriteLine("Results:")

    Console.ReadLine()

     

     

    I have also changed the query so that it has no Where clause at all which should return all records.

     

    No idea why this is not working.

    Saturday, February 23, 2008 5:44 PM

Answers

  • Fixed my own problem, aparently the dataset is an offline/disconnected representation of my database.

     

    I added an adapter, to fill the dataset and now it works fine, here is my working code.

     

    Lines in red indicate the fix.

     

    Code Snippet

    Dim db As New Northwind()

     

    Dim customerAdapter As New NorthwindTableAdapters.CustomersTableAdapter

    customerAdapter.Fill(db.Customers)

     

    Dim matchingCustomers = From cust In db.Customers Where cust.Country Like "*" Select cust

    For Each customer In matchingCustomers

    Console.WriteLine("> {0,33} / {1,30} / {2,4}", _

    customer.CompanyName, customer.ContactName, customer.Country)

    Next

    Console.WriteLine("Results:")

    Console.ReadLine()

     

     

    Saturday, February 23, 2008 6:04 PM