|
-
Aug 6th, 2006, 04:44 AM
#1
Thread Starter
Junior Member
[RESOLVED] [2005] display info on textbox, urgent, pls help if possible
after i set a button to validate the id and password, i wana show the particualrs of that person in repective textboxes
like, name: name of the person
i use tis to do the validation
but i do not noe how to validate 2 fields, id n pw the same time
so after validating, how to do for showing the fields in the textboxes?
----------
Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\project\db1.mdb"
Dim con As OleDb.OleDbConnection
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
Try
Dim strselect As String = "Select Id from member where BId = '" & IdTB.Text & "' and pw='" & pwTB.Text & "'"
'create a new connection
con = New OleDb.OleDbConnection(strcon)
con.Open()
cmd.Connection = con
cmd.CommandText = strselect
dr = cmd.ExecuteReader
Catch eException As Exception
MessageBox.Show(eException.Message)
End Try
------------------------
pls help, i need to submit tis project b4 9am tml >.<
my 1st project on vb so errr..... nothing too complicated pls >.<
-
Aug 6th, 2006, 05:08 AM
#2
Re: [2005] display info on textbox, urgent, pls help if possible
 Originally Posted by kyosugi
after i set a button to validate the id and password, i wana show the particualrs of that person in repective textboxes
like, name: name of the person
i use tis to do the validation
but i do not noe how to validate 2 fields, id n pw the same time
so after validating, how to do for showing the fields in the textboxes?
----------
Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\project\db1.mdb"
Dim con As OleDb.OleDbConnection
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
Try
Dim strselect As String = "Select Id from member where BId = '" & IdTB.Text & "' and pw='" & pwTB.Text & "'"
'create a new connection
con = New OleDb.OleDbConnection(strcon)
con.Open()
cmd.Connection = con
cmd.CommandText = strselect
dr = cmd.ExecuteReader
Catch eException As Exception
MessageBox.Show(eException.Message)
End Try
------------------------
pls help, i need to submit tis project b4 9am tml >.<
my 1st project on vb so errr..... nothing too complicated pls >.<
Hi,
You could try something like:
TextBox1.Text = idTB.Text & pwTB.Text
Hope it helps,
sparrow1
-
Aug 6th, 2006, 05:32 AM
#3
Re: [2005] display info on textbox, urgent, pls help if possible
Once you've created the DataReader you need to read the data from it. You read a row of data and you can then assing the values from the fields of that row to wherever you want, e.g.
VB Code:
'Optimise the command.
dr = cmd.ExecuteReader(CommandBehavior.SingleRow Or CommandBehavior.CloseConnection)
If dr.Read() Then
'The reader contains data.
Me.nameText.Text = dr("Name")
'etc.
End If
dr.Close()
-
Aug 6th, 2006, 08:36 AM
#4
Thread Starter
Junior Member
Re: [2005] display info on textbox, urgent, pls help if possible
i tried but nothing were displayed out
--------
Private Sub EditMember_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =C:\Documents and Settings\Jasmine\My Documents\project\db1.mdb"
Dim con As OleDb.OleDbConnection
Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
Try
Dim strselect As String = "Select Fname, Lname, Address1, Address2, Address3, ContactNo, HandPhNo, Email, CourseOfStudy from member where BorrowerId = '" & EditMemberLog.idTB.Text & "'"
'create a new connection
con = New OleDb.OleDbConnection(strcon)
con.Open()
cmd.Connection = con
cmd.CommandText = strselect
dr = cmd.ExecuteReader(CommandBehavior.SingleRow Or CommandBehavior.CloseConnection)
If dr.Read Then
Me.fNameTB.Text = dr("Fname")
Me.lNameTB.Text = dr("Lname")
Me.add1TB.Text = dr("Address1")
Me.add2TB.Text = dr("Address2")
Me.add3TB.Text = dr("Address3")
Me.hmTB.Text = dr("ContactNo")
Me.hpTB.Text = dr("HandPhNo")
Me.emailTB.Text = dr("Email")
Me.cosCB.Text = dr("CourseOfStudy")
End If
dr.Close()
Catch eException As Exception
MessageBox.Show(eException.Message)
End Try
End Sub
---------------------
did i miss out something?
Last edited by kyosugi; Aug 6th, 2006 at 08:52 AM.
-
Aug 6th, 2006, 08:51 AM
#5
Re: [2005] display info on textbox, urgent, pls help if possible
Then chances are that no records were returned. This is where you have to debug. Put a breakpoint on the first line and step through the code line by line. You can then check whether Read returns True and, if so, what each field contains. If a car is not running properly you start it up and look under the hood. Software is the same.
-
Aug 6th, 2006, 09:39 AM
#6
Thread Starter
Junior Member
Re: [2005] display info on textbox, urgent, pls help if possible
errr......i did not learn how to debug... do noe bout the buttons for step into, out n over, but not sure on how to use them, how do i noe if Read returns True?
-
Aug 6th, 2006, 07:15 PM
#7
Re: [2005] display info on textbox, urgent, pls help if possible
In the code window, click the first line of that code and press F9. This will place a break point on that line. Now, when you run your project it will stop at that line. You can then press the F10 key to step through the code line by line. If you do that you will be able to see whether the code enters the If block or not. If it doesn't then that's a pretty obvious indication of why your TextBoxes are not populated. While execution is stopped you can mouse over variables and properties to see what they contain, plus you can use the Locals and Watch windows to evaluate various expressions. The Locals window displays specific references that are valid in the current context. The Watch window allows you to enter and variable or property name or expression and have it evaluated at the current moment. As you step through the code and values change they are reflected in the Locals and Watch windows. The IDE contains many oter debugging tools too.
Like I said, you can't just look at something and see why it doesn't work in any but the simplest cases. You have to see something in action to diagnose most issues.
If the code doesn't enter the If block then that means that there's an issue with your query because it is not matching any records. What type is the BorrowerId column? Is it text or a number?
-
Aug 6th, 2006, 08:12 PM
#8
Thread Starter
Junior Member
Re: [2005] display info on textbox, urgent, pls help if possible
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|