Retrieving Fields from MS Access

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 6
Reputation: SerapH is an unknown quantity at this point 
Solved Threads: 0
SerapH SerapH is offline Offline
Newbie Poster

Retrieving Fields from MS Access

 
0
  #1
Oct 20th, 2007
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?
Code for retrieving data from Access and displaying it in label or Textbox for the specific user that is logged in the application.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 122
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: Retrieving Fields from MS Access

 
0
  #2
Oct 20th, 2007
as you did here
Dim p As String = rdr(1)
If txtPassword.Text = p Then
you can show the data in lable or textbox
  1. textbox1.text=rdr("column_name")
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 6
Reputation: SerapH is an unknown quantity at this point 
Solved Threads: 0
SerapH SerapH is offline Offline
Newbie Poster

Re: Retrieving Fields from MS Access

 
0
  #3
Oct 22nd, 2007
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


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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 122
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: Retrieving Fields from MS Access

 
0
  #4
Oct 23rd, 2007
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
  1. If txtPassword.Text = p Then
  2.  
  3. MessageBox.Show("Welcome !!")
  4.  
  5. Dim initial As String
  6. initial = Me.txtAccountNo.Text
  7. Dim form2 As Form2
  8.  
  9. ' Create the child form.
  10. form2 = New Form2(initial)
  11. 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
Last edited by manal; Oct 23rd, 2007 at 3:54 pm.
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2955 | Replies: 3
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC