I've currently got three tables, Student, Less/Stu, Lessons and Class
Using sql queries I have managed to use a combo box to return a class code to a text box. Now I have created a SELECT query that should return the values from Lessons that are linked with that Class code. As there are six lessons linked to a class I would like these rows to populate multiple text boxes.
Lesson Code Lesson Name Lesson Credit... are the three columns within the lessons table. So there should be six rows of results to populate the text boxes. The current Code I have
string conString = "DATA SOURCE HERE";
string query = @"SELECT [Lesson ID],[LessonName],[LessonCredits] from Lessons WHERE ClassID ='" + txtClassID.Text + "' ;";
SqlConnection conDateBase = new SqlConnection(conString);
SqlCommand cmdDatabase = new SqlCommand(query, conDateBase);
conDateBase.Open();
SqlDataReader myReader = cmdDatabase.ExecuteReader();
while (myReader.Read())
{
string sLessID = myReader.GetString(myReader.GetOrdinal("Lesson ID"));
string sLessNam = myReader.GetString(myReader.GetOrdinal("LessonName"));
string sLessCred = myReader.GetString(myReader.GetOrdinal("LessonCredits"));
txtLessId1.Text= sLessID;
txtLessName1.Text = sLessNam;
txtLessCred1.Text = sLessCred;
}
This code only returns the last value in the lessons table that is related to the class ID, I have a feeling I need to put the results from the query into a loop then store into an array then assign the text boxes to the array?
Aucun commentaire:
Enregistrer un commentaire