| | |
Retrieving Fields from MS Access
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 6
Reputation:
Solved Threads: 0
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.
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.
as you did here
you can show the data in lable or textbox
•
•
•
•
Dim p As String = rdr(1)
If txtPassword.Text = p Then
VB.NET Syntax (Toggle Plain Text)
textbox1.text=rdr("column_name")
"give only what u willing to receive "
•
•
Join Date: Oct 2007
Posts: 6
Reputation:
Solved Threads: 0
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.

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.
•
•
•
•
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.
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
VB.NET Syntax (Toggle Plain Text)
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
Last edited by manal; Oct 23rd, 2007 at 3:54 pm.
"give only what u willing to receive "
![]() |
Similar Threads
- Data retrieving using ms-access (VB.NET)
- inserting variable value into fields in access? (Visual Basic 4 / 5 / 6)
- Problem with retrieving data from access 2003 (Visual Basic 4 / 5 / 6)
- Date fields imported from access file to excel spreadsheet is converting to number (Visual Basic 4 / 5 / 6)
- updating fields in MS Access (Perl)
- Access INSERT problem (MS Access and FileMaker Pro)
- having problem in retrieving data from MS ACCESS (Visual Basic 4 / 5 / 6)
Other Threads in the VB.NET Forum
- Previous Thread: Interrupt Do While Loop
- Next Thread: CHecking for Duplicates
Views: 2955 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2008 access advanced application array basic beginner browser button buttons center class click client code combo convert cuesent data database datagrid datagridview date datetimepicker design designer dissertation dissertations dissertationtopic eclipse excel exists fade filter forms function html images lib listview map mobile module msaccess net number objects open panel pdf picturebox picturebox2 port position print printing problem read refresh regex richtextbox right-to-left save search serial settings shutdown socket sorting sqldatbase sqlserver studio temperature textbox timer timespan transparency txttoxmlconverter usercontol validation vb vb.net vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web webbrowser winforms winsock wpf wrapingcode xml year





