我有桌子

idteacher idstudent idsubject studentname subjectname teacherame mark


但是如何用表中的信息填充

idteacher teachername
idstudent studentname
idsubject subjectname


mark-仅存在于此表中的字段,然后将其放入datagrid?(我已经创建了datagrid和table(在Visual Studio-> Server Explorer中)

最佳答案

您可能需要数据库中的以下表:

CREATE TABLE teacher (
    idteacher int,
    teachername nchar(50))

CREATE TABLE student (
    idstudent int,
    studentname nchar(50))

CREATE TABLE subject (
    idsubject int,
    subjectname nchar(50))

CREATE TABLE mark (
    idteacher int,
    idstudent int,
    idsubject int,
    mark int)


为了简洁起见,我省略了主键和外键。然后,您将使用以下查询检索DataGrid的数据:

SELECT
    t.idteacher,
    st.idstudent,
    s.idsubject,
    t.teachername,
    st.studentname,
    s.subjectname,
    m.mark
FROM mark m
    INNER JOIN teacher t ON m.idteacher = t.idteacher
    INNER JOIN student st ON m.idstudent = st.idstudent
    INNER JOIN subject s ON m.idsubject = s.idsubject


要将数据加载到DataGrid中,请对上述查询使用Denys的GetData()方法。

10-08 19:04