Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,194 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,035 people online right now. Registration is fast and FREE... Join Now!




Problem getting correct data

 
Reply to this topicStart new topic

Problem getting correct data, have proper sql queries but incorrect code for buttons

DjVw321
23 Sep, 2008 - 01:51 PM
Post #1

New D.I.C Head
*

Joined: 25 Jun, 2008
Posts: 13


My Contributions
I am trying to make a login form that would store a users clearance and difficulty into two separate variables. I have a data set created with the following data
CODE

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:
CODE

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:
CODE

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.
User is offlineProfile CardPM
+Quote Post

DjVw321
RE: Problem Getting Correct Data
26 Sep, 2008 - 12:33 PM
Post #2

New D.I.C Head
*

Joined: 25 Jun, 2008
Posts: 13


My Contributions
can somebody please help me with this
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:25AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month