Data base connectivity and flex grid in vb

13,731 views

Published on

Published in: Education
3 Comments
8 Likes
Statistics
Notes
No Downloads
Views
Total views
13,731
On SlideShare
0
From Embeds
0
Number of Embeds
145
Actions
Shares
0
Downloads
450
Comments
3
Likes
8
Embeds 0
No embeds

No notes for slide

Data base connectivity and flex grid in vb

  1. 1. Database Connectivity using ADODB
  2. 2. Visual Basic 6 ADO Visual Basic 6 obsoletes the previously used database access technology provided by Jet This provides a new one known as ADO or Active Data Objects This technology allows users to access data easily from many existing databases like Oracle or MS SQL Server ADO is quite simple and allows programmers to provide flexible database front ends
  3. 3. Connection Object This object represents an open connection to the data source This connection can be a local connection or can be across a network Key Properties and Methods Property Methods ConnectionString Close Provider Open ConnectionTimeout CommandTimeout CursorLocation Mode
  4. 4. Command Object A command object specifies a specific method you intend to execute on or against the data source accessed by an open connection Key Properties and Methods Property Methods Key Properties and Execute Methods CommandText CommandType
  5. 5. Recordset Object The RecordSet object represents a complete set of records from an underlying base table in the database RecordSet object references only one record at a time as the current record Key Properties and Methods Methods Property CursorLocation AddNew CursorType Close and Open EOF and BOF MoveNext Fields MoveFirst RecordCount MoveLast MovePrevious
  6. 6. Putting These altogether Define and open a Connection to a data source Decide what data you need from the data source and define Command objects that will retrieve this data. Retrieve the data you require by executing the command objects and manipulate the data using RecordSet objects.
  7. 7. Database Connectivity Steps Make a VB application that can be used to connect to database
  8. 8.  Go to components
  9. 9.  Choose Microsoft ADO Data Control 6.0(OLEDB)
  10. 10.  Component is added
  11. 11.  Click on Adodc and go to its properties
  12. 12.  Click on Build
  13. 13.  Select Microsoft Jet 4.0 OLE DB Provider and next
  14. 14.  Select database and test the connection
  15. 15.  From here copy connection string and click ok
  16. 16. Establish ConnectionDim con As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim cmd As New ADODB.CommandPrivate Sub Form_Load()con.ConnectionString ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsAdministratorDesktopEmployee.mdb"con.Openrs.Open "select * from employee", con, adOpenDynamic, adLockOptimisticcmd.ActiveConnection = con
  17. 17. Conti..txt_id = rs.Fields(0)txt_name = rs.Fields(1)txt_desig = rs.Fields(2)txt_add = rs.Fields(3)txt_sal = rs.Fields(4)txt_doj = rs.Fields(5)txt_phn = rs.Fields(6)txt_email = rs.Fields(7)
  18. 18. How to use Flex Grid in VB Go to components
  19. 19.  Choose Microsoft FlexGrid Control 6.0 from components
  20. 20.  Select flexgrid from toolbox and drop it in form
  21. 21.  Select Data tool from tool box and drop it in form
  22. 22.  Select DataSource property of FlexGrid
  23. 23.  Choose DatabaseName from Data tool properties
  24. 24.  Choose your database which you want to use
  25. 25.  Choose Recordset property of Data tool
  26. 26.  Your selected recordset will be shown in flexgrid
  27. 27. How to use data grid in VB Go to components
  28. 28.  Select Microsoft DataGrid Control 6.0(OLEDB)
  29. 29.  Select data grid from tool box and drop in form
  30. 30.  Go to Adodc properties
  31. 31.  Select Microsoft Jet 4.0 ILE Db Provider
  32. 32.  Select database name
  33. 33.  Test the connection
  34. 34.  Go to RecordSource select CommandType as 2- adCmdTable and Table
  35. 35.  Select DataSource from data grid properties
  36. 36.  Your data grid is working
  37. 37. References http://www.w3schools.com http://www.codeproject.com http://msdn.microsoft.com

×