Loading

how to connect to the microsoft access

4 posts / 0 new
Last post
Offline
Joined: 11/21/2009
how to connect to the microsoft access

hello please help me on how to connect in the microsoft access coz i really dont know how to connect im still practicing this vb6..tenks in advance..

renz09's picture
Offline
Joined: 10/24/2009
to connect ms access..

'add reference
'click project then reference then select Microsoft ActiveX Control 2.0 library
'then type the ff. code to General object and Declaration` section...

  1. 'General Declaration
  2. private cn As ADODB.connection
  3. private rs As ADODB.recrdset
  4.  
  5. private sub form_load
  6. Dim cn As String
  7. Dim rs As string
  8. Dim sql As String
  9. Dim cmd As String
  10.  
  11. 'creat a connection string
  12. cmd="provider=Microsoft.jet.3.51OLEDB.3.51;
  13. data source="location of the ms-access database.mdb"
  14.  
  15. 'Esstablish a connection string
  16. set cn = New ADODB.connection
  17. with cn
  18. .connection string=cmd
  19. .open
  20. end with
  21.  
  22. 'Creat Query
  23. sql="sql command"
  24.  
  25. 'open the recordset
  26. set rs= New ADODB.recordset
  27. with rs
  28. .open sql,cn,adOpenFordwardOnly,adLockReadOnly
  29. Do While not rs.EOF
  30.  
  31. 'add the ms access table
  32. text1.additem("database fieldname")
  33. text2.additem("database fieldname")
  34.  
  35.  
  36. 'move to the next record
  37. rs.Movenext
  38. loop
  39.  
  40. 'close the recordset
  41. .close
  42. end with
  43. set rs = Nothing
  44.  
  45. 'close the connection string
  46. cn.close
  47.  
  48. 'destroy the connection object
  49. set cn=Nothing
  50.  
  51. End Sub

Hope this code can help you in your project...........

cidfrey's picture
Offline
Joined: 12/17/2009
Or if you are using adodc and

Or if you are using adodc and datagrid (which is compatible). Right click the adodc bar then choose adodc properties (for the connection string). Then find your MS Access file. Then click test connection then click ok and ok.

Web / System Developer
Contacts :
09327081978
recca_flame05@yahoo.com >>> Facebook/YM
ICCT Colleges Cainta Rizal

Offline
Joined: 04/05/2010
I suggest the ado control is

I suggest the ado control is easy...

Pages

Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.