Fuzz Evans
Fuzz Evans

Reputation: 2943

How do I add and reference a table using LINQ to SQL?

I'm trying to learn LINQ to SQL but having a very difficult time. I ultimately want to have a form that I can add 3 fields to a table, and then call those entries back and store in variables for use. I started my Windows Form Project and added 3 text boxes, and a button that I will have save the values to the database.

I "Added a new connection", Named the Connection, Added a new table on the new connection, Added the Column names, And saved the Table. (I couldn't figure out how to format this better so all the pictures for what I did are below).

Now I see my "TestTable" in the Server Explorer, but I don't know how to use it. How do I get that table from my server explorer to a point that I can Insert, Edit, Delete entries into it. I've seen lots of threads about how to do the actual insert, edit, and delete part, but I'm missing the critical information of how I associate with it. Is it something like creating an object of a class?

//example
ClassTest newTestObject = new ClassTest(); 

enter image description here enter image description here enter image description here enter image description here enter image description here

enter image description here

Upvotes: 1

Views: 774

Answers (1)

KV Prajapati
KV Prajapati

Reputation: 94645

You need to add .dbml (Add new Item + LINQ to SQL Classes), drag table object from server explorer and drop it to dbml sheet. Take a look at tutorial and MSDN article.

Upvotes: 2

Related Questions