[RESOLVED] LINQ Problem probably simple please help.
OK I have been trying to work this out for a while now I am very much learning vb.net and LINQ is part of what we are being told to use for our coursework and it makes sense to use it but its just not working for me. I have added my database.mdf to data sources and added linq to sql and added all the tables in the database as data source objects. Anyway I think I did something wrong but I can't see what it is all I want to do is retrieve the company names at this stage and I can build on that myself but I can't get it to work.
This is what my VS looks like hope someone can spot something I didn't.
http://i.imgur.com/u4I8yl.jpg
P.S. I am very stupid yes...
Re: LINQ Problem probably simple please help.
You can combine LINQ2SQL with datasets, but usually you don't. You generally just need to create a datacontext and pull your data from that. Usually the datacontext will be named based on what you named the dbml file. So in yours it looks like it is DataClass.dbml, so there SHOULD be a DataClassDataContext class you can create an instance of.
Code:
Using myDataContext As New DataClassDataContext
Dim comp = From C In myDataContext.Companies
Select C.Name Distinct
Return comp
End Using
1 Attachment(s)
Re: LINQ Problem probably simple please help.
OK I half understand what you mean is there anywhere I can learn more about what you are trying to explain? because I am still not fully with you I don't want to take any more of your time up if there is already something out there to explain what you mean.
This is the program I am working on just now if anyone is interested its very unfinished the final program will need to query the database and display the results. What I am stuck on just now is getting a basic starting point with the LINQ/Sql
Attachment 83547
Re: LINQ Problem probably simple please help.
returning comp.ToString is going to return the SQL syntax string that LINQ is using to query your database, which of course is not what you want. To see it working properly, change your function to this:
Code:
Public Function GetCompNames()
Using myDataContext As New DataClassDataContext
Dim comp = From C In myDataContext.Companies _
Select C.Name Distinct
Return comp.ToArray
End Using
End Function
and change your form_load in your GUI form to this:
Code:
Private Sub GUI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Populate the filter boxes
Populate.ResetFilters()
Populate.PopulateLists()
TxtDebug.Text = String.Join(",", Sql.GetCompNames)
End Sub
Re: LINQ Problem probably simple please help.
Thanks for taking the time to look at that man, I will check it out in the morning and let you know how it goes just checking the thread on my laptop in bed before I go sleep as I couldn't stop thinking about it :D
EDIT: Just tested it thanks a lot got me moving again :D