1. Create two Relational Tables, student and class tables. Students and course schedules, as shown in the example.
2. Create a form in vs2010.
And writeCodeAs follows:
Namespace Linqtest
{
Public Partial Class Frmmanytomany: Form
{
Internal Static String Sqlconstr = @" Data Source = localhost; initial catalog = lxpower; user = sa; Pwd = " ;
Public Frmmanytomany ()
{
Initializecomponent ();
}
Private VoidFrmmanytomany_load (ObjectSender, eventargs E)
{
Binddata ();
}
Private Void Binddata ()
{
Dataclasses1datacontext DB =New Dataclasses1datacontext (sqlconstr );
VaR Q = From C In DB. Student
Join o In DB. oclass on C. studentname equals O. studentname
Select New {C. ID, C. studentname, O. Class };
This . Maid = Q;
}
}
}
Here we use the LINQ to SQL statement. In fact, you can use datacontent for relational purposes.
The running result is as follows::
Is the relationship between the two tables very simple and may encounter many problems in actual operations? We can discuss the following:
For original works, please indicate the source for reprinting !!!