Solved

Query an Access database using LinQ in Visual Basic 2012

Posted on 2014-04-29
8
834 Views
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?

Thanks,
Brooks
0
Comment
Question by:gbnorton
  • 5
  • 3
8 Comments
 
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?
0
 

Author Comment

by:gbnorton
ID: 40032019
Intellisense  displays the dataset, but not the table name.  Attached is a screenshot of the dataset designer.
dataset-designer.jpg
0
 
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

        adap.Fill(table)

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

Open in new window

0
 

Author Comment

by:gbnorton
ID: 40032829
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 52

Accepted Solution

by:
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.
0
 

Author Comment

by:gbnorton
ID: 40042176
No joy.  Please take a look at the attachment.  
Thank you,
Brooks
Linq.jpg
0
 

Author Comment

by:gbnorton
ID: 40047250
Carl,
I've been reading and reading but unable to move forward.  Any ideas?
thanks,
Brooks
0
 

Author Closing Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now