[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 993
  • Last Modified:

Query an Access database using LinQ in Visual Basic 2012

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?

Thanks,
Brooks
0
gbnorton
Asked:
gbnorton
  • 5
  • 3
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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?
0
 
gbnortonAuthor Commented:
Intellisense  displays the dataset, but not the table name.  Attached is a screenshot of the dataset designer.
dataset-designer.jpg
0
 
Carl TawnSystems and Integration DeveloperCommented:
Just had a play around. It should be more like:
        Dim adap As New Project3dbdatasetTableAdapters.EvilCharactersTableAdapter()
        Dim table As New Project3dbdataset.EvilCharactersDataTable

        adap.Fill(table)

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

Open in new window

0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
gbnortonAuthor Commented:
Almost there.  What is in SL1?  I tried to see it using:
Msgbox(SL1)

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

The column SkillLevel is type number.

I appreciate your help.
Brooks
0
 
Carl TawnSystems and Integration DeveloperCommented:
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.
0
 
gbnortonAuthor Commented:
No joy.  Please take a look at the attachment.  
Thank you,
Brooks
Linq.jpg
0
 
gbnortonAuthor Commented:
Carl,
I've been reading and reading but unable to move forward.  Any ideas?
thanks,
Brooks
0
 
gbnortonAuthor Commented:
I was not able to get this working but appreciate you looking at it.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now