Query an Access database using LinQ in Visual Basic 2012

Posted on 2014-04-29
Last Modified: 2016-02-15
I am in a Visual Basic class learning about querying an Access database using LinQ.  And struggling.  I have an Access database.  I have added it as a datasource in my project.  Now I want to query the table and write the result to a variable.
The dataset name is Project3dbdataset.
The column names are Character, SkillLevel, Level, Score, and Damage

Here is my code:
Dim SL1 = From txtSkillLevel In Project3dbdataset
        Where Character = 7
        Select SkillLevel

It fails at Dim SL1 = From txtSkillLevel In Project3dbdataset
with error
Project3dbdataset is a type and cannot be used as an expression.

How do I access the dataset with the query?

Question by:gbnorton
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 52

Expert Comment

by:Carl Tawn
ID: 40031434
The dataset contains (potentially) multiple tables, so you should be specifying DataSetName.SomeTableName.

Intellisense should be your friend here. If you still have trouble can you open your dataset designer and post a screengrab of it?

Author Comment

ID: 40032019
Intellisense  displays the dataset, but not the table name.  Attached is a screenshot of the dataset designer.
LVL 52

Expert Comment

by:Carl Tawn
ID: 40032163
Just had a play around. It should be more like:
        Dim adap As New Project3dbdatasetTableAdapters.EvilCharactersTableAdapter()
        Dim table As New Project3dbdataset.EvilCharactersDataTable


        Dim SL1 = From item In table
                    Where item.Character = 7
                    Select item.SkillLevel

Open in new window

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 40032829
Almost there.  What is in SL1?  I tried to see it using:

but get the error "Prompt cannot be converted to type string."

The column SkillLevel is type number.

I appreciate your help.
LVL 52

Accepted Solution

Carl Tawn earned 500 total points
ID: 40034025
It will be type defined in the underlying database column. The syntax you have been using is using a Variant datatype.

You should also be able to use the following to make it explicitly numeric:
        Dim SL1 As Integer = From item In table
                    Where item.Character = 7
                    Select item.SkillLevel

Open in new window

Or, you could call ToString() on the existing SL1 to cast it to string for the message box call.

Author Comment

ID: 40042176
No joy.  Please take a look at the attachment.  
Thank you,

Author Comment

ID: 40047250
I've been reading and reading but unable to move forward.  Any ideas?

Author Closing Comment

ID: 40064949
I was not able to get this working but appreciate you looking at it.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert VB web project to C# 3 65
FTP recursive download files 5 26
Help with Report Viewer in VS2013 6 32
Datagridview column resizing 8 25
Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question