VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Few questions on updating datas into Access Posted by desmondband on 9 Jul 2007 at 3:48 AM
Hi guys, i have a few question listed below:

I have username and password textbox in a form. When i click the login button on the same form, it has to connect to the database and retrieve the data, matching both username and password and at the end determine whether to display the next form.

1. How do i connect the database?
2. What coding must i type into the Login button, eg: connect to the database (mdb.open or what-so-ever)

Will be apprecate if could type me a example!

Thanks thanks!!
Report
Re: Few questions on updating datas into Access Posted by dokken2 on 9 Jul 2007 at 4:35 AM
: Hi guys, i have a few question listed below:
:
: I have username and password textbox in a form. When i click the
: login button on the same form, it has to connect to the database and
: retrieve the data, matching both username and password and at the
: end determine whether to display the next form.
:
: 1. How do i connect the database?
: 2. What coding must i type into the Login button, eg: connect to the
: database (mdb.open or what-so-ever)
:
: Will be apprecate if could type me a example!
:
: Thanks thanks!!
:

can use ADO or DAO - DAO is a little faster for Access/Jet databases but ADO gives you more flexibility.


'ADO
'required reference to [microsoft activex data object 2.x library]
Public Sub AdoConnectSecureDB()
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Dim sCon As String
Dim ErrCount As Byte

On Error GoTo erh
ErrCount = 0

'CONNECTION STRING
'9/12/02 - ADO CONNECTION TO A SECURE ACCESS DB w/ WORKGROUP
'sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
' "User ID=ACCOUNT;Password=PASSWORD;" & _
' "Data Source=C:\MyMDB.mdb;" & _
' "Persist Security Info=False;" & _
' "Jet OLEDB:System database=c:\system.mdw"

'CONNECTION STRING
'9/12/02 - ADO CONNECTION TO AN ACCESS DB
sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"User ID=Admin;Password=;" & _
"Data Source=C:\db1.mdb;" & _
"Persist Security Info=False;"

'CREATE NEW CONNECTION
Set cn = New ADODB.Connection
'OPEN CONNECTION WITH CONNECTION STRING
cn.Open sCon
'CREATE NEW RECORDSET
Set rs = New ADODB.Recordset
'OPEN RECORDSET
rs.Open "table1", cn, adOpenDynamic, adLockOptimistic, adCmdTable
rs.MoveFirst

'TRAVERSE RECORDS
Do While Not rs.EOF
msgbox rs!Field1
rs.MoveNext
Loop

'CLOSE/RELEASE RESOURCES
xit:
If rs.State <> adStateClosed Then rs.Close
If cn.State <> adStateClosed Then cn.Close
xit2:
Set rs = Nothing
Set cn = Nothing
Exit Sub

erh:
ErrCount = ErrCount + 1
MsgBox Err.Description, vbCritical, Err.Number
If ErrCount > 1 Then Resume xit2 Else Resume xit
End Sub



'DAO
'Need to set a reference to-
'Microsoft DAO 3.6 Object Library
Sub ConnectDAO()
Dim wk As DAO.Workspace
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set wk = DAO.DBEngine(0)
Set db = wk.OpenDatabase("d:\db2.mdb") 'OPEN DB
'Set rs = db.OpenRecordset("table1", dbOpenSnapshot) 'READONLY
Set rs = db.OpenRecordset("table1", dbOpenDynaset) 'WRITE

rs.AddNew 'ADD A NEW RECORD
rs!FIELD1 = "new rec" 'ASSIGN VALUE TO A FIELD
rs.Update 'UPDATE/SAVE RECORD TO TABLE

'rs.Edit 'EDIT RECORD
'rs!FIELD1 = "changed rec" 'ASSIGN NEW VALUE
'rs.Update 'UPDATE/SAVE

'TRAVERSE AND OUTPUT RECORDS
'Do While Not rs.EOF
' MsgBox rs!FIELD1
' rs.MoveNext
'Loop

rs.Close
db.Close
wk.Close
Set rs = Nothing
Set db = Nothing
Set wk = Nothing
End Sub
Report
Re: Few questions on updating datas into Access Posted by desmondband on 9 Jul 2007 at 5:28 PM
Hihi, in this code, where should i type in the code for my login button for the function to check the username and password?
let say my login button is

btn Login,
Username textfield = TBusername
Password textfield = TBPassword

thanks!!

: : Hi guys, i have a few question listed below:
: :
: : I have username and password textbox in a form. When i click the
: : login button on the same form, it has to connect to the database and
: : retrieve the data, matching both username and password and at the
: : end determine whether to display the next form.
: :
: : 1. How do i connect the database?
: : 2. What coding must i type into the Login button, eg: connect to the
: : database (mdb.open or what-so-ever)
: :
: : Will be apprecate if could type me a example!
: :
: : Thanks thanks!!
: :
:
: can use ADO or DAO - DAO is a little faster for Access/Jet databases
: but ADO gives you more flexibility.
:
:
: 'ADO
: 'required reference to [microsoft activex data object 2.x library]
: Public Sub AdoConnectSecureDB()
: Dim cn As ADODB.Connection, rs As ADODB.Recordset
: Dim sCon As String
: Dim ErrCount As Byte
:
: On Error GoTo erh
: ErrCount = 0
:
: 'CONNECTION STRING
: '9/12/02 - ADO CONNECTION TO A SECURE ACCESS DB w/ WORKGROUP
: 'sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
: ' "User ID=ACCOUNT;Password=PASSWORD;" & _
: ' "Data Source=C:\MyMDB.mdb;" & _
: ' "Persist Security Info=False;" & _
: ' "Jet OLEDB:System database=c:\system.mdw"
:
: 'CONNECTION STRING
: '9/12/02 - ADO CONNECTION TO AN ACCESS DB
: sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
: "User ID=Admin;Password=;" & _
: "Data Source=C:\db1.mdb;" & _
: "Persist Security Info=False;"
:
: 'CREATE NEW CONNECTION
: Set cn = New ADODB.Connection
: 'OPEN CONNECTION WITH CONNECTION STRING
: cn.Open sCon
: 'CREATE NEW RECORDSET
: Set rs = New ADODB.Recordset
: 'OPEN RECORDSET
: rs.Open "table1", cn, adOpenDynamic, adLockOptimistic, adCmdTable
: rs.MoveFirst
:
: 'TRAVERSE RECORDS
: Do While Not rs.EOF
: msgbox rs!Field1
: rs.MoveNext
: Loop
:
: 'CLOSE/RELEASE RESOURCES
: xit:
: If rs.State <> adStateClosed Then rs.Close
: If cn.State <> adStateClosed Then cn.Close
: xit2:
: Set rs = Nothing
: Set cn = Nothing
: Exit Sub
:
: erh:
: ErrCount = ErrCount + 1
: MsgBox Err.Description, vbCritical, Err.Number
: If ErrCount > 1 Then Resume xit2 Else Resume xit
: End Sub
:
:
:
: 'DAO
: 'Need to set a reference to-
: 'Microsoft DAO 3.6 Object Library
: Sub ConnectDAO()
: Dim wk As DAO.Workspace
: Dim db As DAO.Database
: Dim rs As DAO.Recordset
:
: Set wk = DAO.DBEngine(0)
: Set db = wk.OpenDatabase("d:\db2.mdb") 'OPEN DB
: 'Set rs = db.OpenRecordset("table1", dbOpenSnapshot) 'READONLY
: Set rs = db.OpenRecordset("table1", dbOpenDynaset) 'WRITE
:
: rs.AddNew 'ADD A NEW RECORD
: rs!FIELD1 = "new rec" 'ASSIGN VALUE TO A FIELD
: rs.Update 'UPDATE/SAVE RECORD TO TABLE
:
: 'rs.Edit 'EDIT RECORD
: 'rs!FIELD1 = "changed rec" 'ASSIGN NEW VALUE
: 'rs.Update 'UPDATE/SAVE
:
: 'TRAVERSE AND OUTPUT RECORDS
: 'Do While Not rs.EOF
: ' MsgBox rs!FIELD1
: ' rs.MoveNext
: 'Loop
:
: rs.Close
: db.Close
: wk.Close
: Set rs = Nothing
: Set db = Nothing
: Set wk = Nothing
: End Sub
:

Report
Re: Few questions on updating datas into Access Posted by desmondband on 10 Jul 2007 at 4:01 AM
how about using a oledb connection?
: Hi guys, i have a few question listed below:
:
: I have username and password textbox in a form. When i click the
: login button on the same form, it has to connect to the database and
: retrieve the data, matching both username and password and at the
: end determine whether to display the next form.
:
: 1. How do i connect the database?
: 2. What coding must i type into the Login button, eg: connect to the
: database (mdb.open or what-so-ever)
:
: Will be apprecate if could type me a example!
:
: Thanks thanks!!
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.