StudentID, StudentName, TeacherID, Clearance, Difficulty 2, Dan, 1, 1, 1 3, Jodi, 2, 2, 2 4, Karen, 3, 3, 3 5, Jhonnie, 2, 1, 3 6, Timmy, 1, 4, 2
In my form there are two combo boxes which contain the students names and the teachers names. When the teachers name is selected the students in that class are put into the second list box and it is enabled so that the student can select their name from that classroom. When the student selects their name and hits the login button i want it to put their values for their difficulty and clearance into variables. Then, for debugging purposes i have it assign the variables to three different labels' text property. I have the sql queries made and they work fine when i execute them in the data preview window and sql query builder. Here they are:
SELECT Clearance FROM Student WHERE (StudentID = @Param2) SELECT Difficulty FROM Student WHERE (StudentName = @Param2) SELECT StudentID FROM Student WHERE (StudentName = @Param2) SELECT StudentName, StudentID, TeacherID, Clearance, Difficulty FROM Student WHERE (TeacherID = @Param1)
When I run the program, select the student and teacher names and press the button I get an incorrect value for my clearance. For example if i have Timmy selected i should get a number 4 assigned to my clearance but instead i get 1. Here is my code for the form:
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'StudentLoginDataSet.Student' table. You can move, or remove it, as needed. Me.StudentTableAdapter.Fill(Me.StudentLoginDataSet.Student) 'TODO: This line of code loads data into the 'StudentLoginDataSet.Teacher' table. You can move, or remove it, as needed. Me.TeacherTableAdapter.Fill(Me.StudentLoginDataSet.Teacher) End Sub Private Sub TeacherNameComboBox_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TeacherNameComboBox.SelectedIndexChanged Try Me.StudentTableAdapter.StudentName(Me.StudentLoginDataSet.Student, CType(TeacherNameComboBox.SelectedValue, Integer)) Catch ex As System.Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try StudentNameComboBox.Enabled = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click studentname = StudentNameComboBox.Text studentid = CType(StudentNameComboBox.SelectedValue, Integer) '' Student ID is the selected value for studentnamecombobox clearance = StudentTableAdapter.Clearance(StudentLoginDataSet.Student, studentid) Label1.Text = studentname Label2.Text = studentid Label3.Text = clearance End Sub End Class
Like i stated before i get a correct value in the query builder and data preview but when i execute the program something is wrong. The student ID shows up properly however if i use my sql query to get that data from the table it will not give right value for that either.