57 Replies
What's the error actually referencing?
It said that the error referencing 'CustomerDBDataContext' could not be found in a type or a namespace
I'm currently learning how to connect to a database by using linq to sql but the teacher haven't teach me enough anything on how to use it yet
Idk how to show the data on screen
you got any ideas?
Can you show the error?
It sounds like you're missing a using statement in that file
that doesn't really give any extra information 🙂
click on CustomerDBDataContext, then press ctrl + .
that should give you a list of possible fixes, I would imagine one is to add a using statement for the namespace where you've created CustomerDBDataContext
yea that doesn't help much
?
Does this class, actually, y'know, exist?
no?
I'm trying to follow instruction but I hit a dead end on what to do next
Then how do you want to use it...?
I want to use the database to extract data out so I can print them on screen
Cool, read up on how to use EF Core properly, then
EF core?
That's what you're trying to use to get data from the database, no?
wait so I have to create a getter setter for the database?
Entity Framework Core?
You have to create the context, first of all
well the teacher instruct me to connect to the database using linq to sql
Or, if you want to start from an existing database, you can generate it
Ah, oof, linq2sql...
Well, look up the docs of that, then
damn, all of the tutorials on youtube showing how to use linq to sql by using a windows form something, I'm only here to use net core or frame work
Code is code, it's not that different
Do adapt it to your setup
Or, as I said, read the documentation instead of looking up YT tuts
I'm better suited when it comes to visual learner
Tough
I wish some python knowledge could translate these c# code xD
but they are not on the same subject rn ;v;
I think I fixed it with switch from net core to framework
but a new problem arise
@SinFluxx got any ideas?
In your connection string I believe it should be "Data Source" not "DataSource"
look's like it works?
it doesn't doesn't show any data for some reason
how do I check the data inside manually?
in SQL there's data but in C# it doesn't show any dafuq?
How? @sn0wgirl_97
I need your help on this
how did you add it into Server Explorer
@Yasaki Kondo (Kei Kanna) Do you know how to find the connection string of your DB?
And once you got the connection string, this link explains the basic steps to connect to your DB.
Other links on this page guide you to fetch the DB data.
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/linq/how-to-connect-to-a-database
How to: Connect to a Database - ADO.NET
Learn how to use DataContext to connect to a database in LINQ to SQL. Refer to these examples to use DataContext to connect to a database and to get rows.
I open sql and add in northwind with the given file (northwind.sql)
and log in with the same account and try to add connection to it
Do you know your connection string?
uh, let me check
uh this pop up
You can open it as admin but i don't think that s what you need to do
didn't I already give all permission to all users I created?
I think i can help you, maybe, but first i need to understand
I know that using databases can be hard if you are not used to it
It's my first time working with one :3
currently I have no connection rn
First of all, i see on the previous image that you are opening the Sql express DB "sqlexpress.northwind",
But on the other end i see in your solution that your dbml talks about DataClasses1.
So my first question would be : where are the data you want to fetch?
from the northwind.mdf
but at first it wasn't showing any data
so I'm try something else
So you made the connection with northwind successfully ?
this was probably an empty List
I think?, it show the collumns and rows
but I see no data on it
No, what you see is the DB
So, when you connect your Visual studio on your Sql database, the two are linked okay
But if you want to fetch data from your database with your code, you need to make also the "connection" in your code, and that's why we use a connection string
oh it's something like using ("")?
So what you need first is to get your connection string, i think.
So what you can do is click on SQL server explorer and find in the tree where your northwind db is
find the tree?
sorry, I still learning english xD
the hierarchy tree wait a second
I will give you a screenshot
ok
See if you can find something like this.
Explanation :
1) I am on "PHILDESKTOP(SQL SERVER)" thats basically my SQL Server
2) I am in the folder Databases
3) And in the previous folder, there are my databases.
What you need when you find it, is left click on the arrow next to your database name (northwind) so that it "expands" its content, and then you right click on the name northwind and you click Properties
Here, Sandbox is the name of my db (northwind for you)
If you succeed in seeing the Properties of your Database, then there is a property in the "Properties" window that says "Connection string" in one column and in the other column, there is your connection string.
It will not exactly be the same for you, i must tell, because I use sql server and you seem to use SQL Express
Probably this actually ?
that's the just database I connected to
through account
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.