简体   繁体   中英

Extra columns showing up in DataGridView but not showing in SQL

I am doing a Windows form program with visual studio and have started using LINQ for the first time, I have a database which has been set up in SQL Server and have linked it to my program in visual studio.

I have added a DataGridView to my form and put in the following code to load one of the database tables into the DGV in the form load event.

  LINQDataClassesDataContext DB = new LINQDataClassesDataContext();
    var test (from s in DB.Student_Courses select s);
    dgvDataTab1.DataSource = test;

the table data loads into the DGV but with 2 extra columns on the end "Course" and "Student" https://gyazo.com/212646a0f43c2588d4413bef33b24f5b

But when a run a SQL query on this table in SQL Server those 2 extra columns do not show.

I also noticed under the LINQDataClasses in the solution explorer the Student_Course table has 2 EntityRef which i do not know what they are or how they got their.

Has anyone else come up against this? and if so how to remove them but still be able to add/edit in the DataGridView.

hers a link to my database added with LINQ https://gyazo.com/ae1959f18c4647525036c3070f6a8f07

Kind Regards Michael

Can you do a projection?

LINQDataClassesDataContext DB = new LINQDataClassesDataContext();
var test = (from s in DB.Student_Courses select new { SID, CID , Mark } );
dgvDataTab1.DataSource = test;

Can you hide those columns?

dgvDataTab1.Columns["Course"].Visible = false
dgvDataTab1.Columns["Student"].Visible = false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM