Well-known member
Nov 29, 2018
Programming Experience
Hi All
This is a cross post between database and C#
I am writing a student app and I want to have a datagridview for all the letters sent out per student number.
On the datagridview I want a combo box that lists all the available types of letters but it must default to the letter that was sent and the date.
I have a table with all the possible kinds of letters and another table with the student number. letter type and date.
So I only want to list the letters sent to that specific student and the dates
The reason why I want all of the kinds of letters listed is because at the end of the datagridview they must be able to add a new letter

I searched a bit and it seems I need to use joins

I will attach my code, I am getting hopefully lost. It is my first project

conn = new SqlConnection(cs.DBConn);
            cmd = new SqlCommand("select Letters.LetterName, StudentLetter.LetterNumber, StudentLetter.DateSent  from Letters, StudentLetter, Personaldata OUTER JOIN StudentLetter.LetterNumber  ON Letter.LetterName WHERE StudentLetter.StudentNumber='" + studentNumberUpdater + "'", conn);
            SqlDataAdapter myDA = new SqlDataAdapter(cmd);
            DataSet myDataSet = new DataSet();
            dgvLetters.DataSource = myDataSet.Tables[0].DefaultView;


Any assistance will be appreciated
Please provide the relevant schema of all the relevant tables, i.e. each table you want to draw data from, their primary and foreign key columns and any other columns you want to display. I suspect that you will need to use a join to populate the DataGridView with data from multiple tables and then you will need a second query to produce the list of possible letters with which to populate the combo box column.
Top Bottom