954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

displaying database records in new form

hey guys, im having a little problem here.
here's my code so far:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        con = New SqlConnection("Data Source=.\SQLExpress;Integrated Security=true; AttachDbFilename=C:\Users\Carlo\Documents\Visual Studio 2008\Projects\OTTO Payroll System\OTTO Payroll System\OTTOdBase.mdf;User Instance=true")
        con.Open()

            Try

                If CType(Me.ACCESSTableAdapter.ScalarQuery1(Me.UserBox.Text, _
                         Me.PassBox.Text, Me.PosBox.SelectedItem), Integer) > 0 Then
                    If PosBox.SelectedItem = "Administrator" Then
                        Dim form As New Form2
                        form = New Form2
                        Form2.Show()
                        Me.Hide()
                    ElseIf PosBox.SelectedItem = "Accountant" Then
                        Dim form As New Form3
                        form = New Form3
                        Form3.Show()
                        Me.Hide()
                    ElseIf PosBox.SelectedItem = "Employee" Then

                    com = New SqlCommand("Select * from EMPLOYEE", con)
                    dr = com.ExecuteReader()
                    Form4.Show()
                    While dr.Read()
                        Form4.Label1.Text = (dr(0).ToString())
                        Form4.Label2.Text = (dr(1).ToString())
                        Form4.Label3.Text = (dr(2).ToString())
                    End While

                    ElseIf PosBox.SelectedItem = "" Then
                        MessageBox.Show("Please select a position", "Choose a position", MessageBoxButtons.OK, MessageBoxIcon.Information)

                    End If
                Else
                    MsgBox("Invalid Username/Password and/or No Position Selected.")

                End If
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try

    End Sub


what i wanted to do is, when an "employee" access the system by logging in, a form will show showing his record. my problem is that, whatever employee account i use, the same information are being displayed on form 4 which is the first record on the database. i want the form4 to display the records of whatever employee account i use. pls help me. . .

raiko098
Newbie Poster
3 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

You need a unique identifier all your doing is selecting the entire database. you need something like
com = New SqlCommand("Select * from EMPLOYEE", con) Where emp_id = 'session.id'

freshfitz
Posting Pro in Training
436 posts since Sep 2008
Reputation Points: 12
Solved Threads: 36
 

I see.
But what do you actually mean by 'session.id'?
Would I be using the exact same code that you typed or do I need to make my own identifier?

And if I were to make my own identifier, will it come from the database? For example, if the Emp_ID is 1001, would 1001 be the identifier?

raiko098
Newbie Poster
3 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Why don't use dataset, and dataset's query wizards? It is much simplier to make SQL queries.
It seems you don't have SQL knowledges, so I hardly suggest you to use dataset wizards.

martonx
Junior Poster in Training
51 posts since May 2008
Reputation Points: 10
Solved Threads: 8
 

use a condition with a feild in sqlcommand

abhishekcs
Newbie Poster
5 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You