Hi

I am creating an MDI application that carries out various tasks >> Login, View Balance, Show Transactions, Request Statement.

So far I have only managed to create the Parent MDI, Main menu to be able to choose a function, and login validation.

Login Code:

Dim str As String = "Provider = Microsoft.jet.OLEDB.4.0;Data Source =C:\....\bin\CustomerDetails.mdb"
Dim conn As New OleDb.OleDbConnection(str)


Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

Dim cmd As New OleDb.OleDbCommand("select * from SecurityTable where AccountNo='" + txtAccountNo.Text + "'", conn)

conn.Open()


Try
Dim rdr As OleDb.OleDbDataReader = cmd.ExecuteReader
If rdr.Read Then

Dim p As String = rdr(1)
If txtPassword.Text = p Then

MessageBox.Show("Welcome !!")
Me.Close()

Else
MsgBox(" Invalid Password!! Please try again ")
txtPassword.Text = ""
txtPassword.Focus()
End If

Else
MsgBox(" Invalid Username!! Please try again ")
txtAccountNo.Text = ""
txtPassword.Text = ""
txtAccountNo.Focus()
End If

conn.Close()

Catch ex As Exception
MsgBox(ex.Message)
conn.Close()
End Try

End Sub


The above code works successfully. It retrieves data from MS Access Security Table and allows the user to access the main menu commands in the Parent form.

The PROBLEM that I have now is in retrieving specific records/fields for that particular user that is logged in.


For example, I have created a form named Balance which is displayed once the miViewBalance is clicked. In it I want to show in a label or TextBox the Name, Surname and Balance for that specific user.

I already have a MS Access Table that contains the details such as name, surname, address, account type, etc. All I want is to display some fields in the Balance Form.

CAN ANYBODY HELP ME WITH THE CODE PLEASE?:S
Code for retrieving data from Access and displaying it in label or Textbox for the specific user that is logged in the application.

as you did here

Dim p As String = rdr(1)
If txtPassword.Text = p Then

you can show the data in lable or textbox

textbox1.text=rdr("column_name")

Hi there Manal :)

I managed like you said!

Twisted the code around to make it appropriate for the View Balance bit, as follows :


Private Sub btnBalance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBalance.Click

Dim cmd As New OleDb.OleDbCommand("select AccountNo,Password,Title,Name,Surname from AccountDetails where AccountNo='" + txtAccountNo.Text + "'", conn)

conn.Open()


Try
Dim rdr As OleDb.OleDbDataReader = cmd.ExecuteReader
If rdr.Read Then

Dim p As String = rdr(1)
If txtPassword.Text = p Then

Label3.Text = rdr(2)
Label4.Text = rdr(3)
Label5.Text = rdr(4)

This way ... once the form is uploaded and the user re-enters the account no and password ... details will be shown.

You had already replied to my previous post, but I wasn't getting anywhere. Second time around I managed ... so THANKS A lot :P


Just want to add ....

I don't know if you can help .... is there a way how I can eliminate re-entering the account no and password in the Balance form.

Example .... to get data from Login form entries. This way the user does not have to re-enter his login details.

I don't know if you can help .... is there a way how I can eliminate re-entering the account no and password in the Balance form.

Example .... to get data from Login form entries. This way the user does not have to re-enter his login details.

what I understand that you have two forms , one for logging in and the other one to show information for corresponding user , right?
then yes it is better to eliminate re-entering account's information in the other form , or there will be no need for log in form , you can pass the value you got in first parent form(log in form) to the child form(balance_info form)) ,
you can pass the txtAccountNo.text as parameter for the child form's constructor

If txtPassword.Text = p Then

                    MessageBox.Show("Welcome !!")

                     Dim initial As String
                    initial = Me.txtAccountNo.Text
                    Dim form2 As Form2

                    ' Create the child form.
                    form2 = New Form2(initial)
                    form2.Show()

in the form2 you need to overload the constructor
read this artical to show you how you can pass values between forms(or any objects)

good luck :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.