User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 456,552 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,477 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 1990 | Replies: 3
Reply
Join Date: Oct 2007
Posts: 6
Reputation: SerapH is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SerapH SerapH is offline Offline
Newbie Poster

Question Retrieving Fields from MS Access

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2006
Posts: 117
Reputation: manal is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: Retrieving Fields from MS Access

  #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
textbox1.text=rdr("column_name")
"give only what u willing to receive "
Reply With Quote  
Join Date: Oct 2007
Posts: 6
Reputation: SerapH is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SerapH SerapH is offline Offline
Newbie Poster

Solution Re: Retrieving Fields from MS Access

  #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  
Join Date: Mar 2006
Posts: 117
Reputation: manal is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: Retrieving Fields from MS Access

  #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
           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 "
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 5:17 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC