TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ivan Climov
1.1k
692
22.4k
How to filter “table_2” depending on the selected entry in “
Feb 23 2019 1:03 AM
I'm using:
- Entity Framework v6.2.0;
- SQL Server 2012;
- C#.
I have these tables:
- tbl_01_Groups;
- tbl_02_Students;
- tbl_03_GroupsStud;
The tbl_01_Groups table is displayed in dataGridView1. One student can be in several groups.
To solve this problem, I suspect that it is necessary to build the table of relations tbl_03_GroupsStud.
Question:
how to make
dataGridView2
display
table_2
records that belong to the group selected in
dataGridView1
?
Requirements for
table_2
:
1.
table_2 should contain the following fields:
[tbl_02_Students].[NameStud];
[tbl_02_Students].[Property_1];
[tbl_01_Groups].[nameGroup];
... other columns as needed
2.
if changes are made in the
table_2
record, then these changes are displayed in the original source;
3.
if an entry is added to the
table_2
, then this entry is displayed in the source;
Table_2
is planned to be used in another query.
How to make the
table_2
meet the above requirements?
Something like I managed to do with the help of queries in MSAccess:
Request
req_GroupsStud_Stud
:
SELECT
tbl_03_GroupsStud.*, tbl_02_Students.NameStud
FROM
tbl_03_GroupsStud
INNER
JOIN
tbl_02_Students
ON
tbl_03_GroupsStud.id_stud = tbl_02_Students.id_stud;
Request
req_GroupsStud_CurGroup
:
SELECT
req_GroupsStud_Stud.*, req_GroupsStud_Stud.id_group
FROM
req_GroupsStud_Stud
WHERE
(((req_GroupsStud_Stud.id_group)=[Forms]![frm_00_00_MainForm]![id_group_Frm]));
From the form, using the expression
[Forms]![Frm_00_00_MainForm]![Id_group_Frm]
, the parameter
[id_group_Frm]
is passed to the request.
I don’t understand how to do the same thing using the entity-framework and MS SQL Serever.
My code
ContextDB cntxtDB;
public
Frm1UC()
{
InitializeComponent();
cntxtDB =
new
ContextDB();
}
private
void
Frm1UC_Load(
object
sender, EventArgs e)
{
Fill_dataGridView1();
}
public
void
Fill_dataGridView1()
{
try
{
cntxtDB.tbl_01_Groups.Load();
bs_Grid1.DataSource = cntxtDB.tbl_01_Groups.Local.ToBindingList();
dataGridView1.DataSource = bs_Grid1;
}
catch
(Exception ex)
{
string
s = ex.Message;
string
t = ex.StackTrace;
// throw;
MessageBox.Show(s);
}
}
https://imageshost.ru/image/Mbssq
https://imageshost.ru/image/Mb936
https://imageshost.ru/image/Mb7DW
https://imageshost.ru/image/MbWj7
Reply
Answers (
0
)
Create a Trip Calculator Windows application that can be use
sending mail through c#