Click here to load reader

Data base connectivity and flex grid in vb

Embed Size (px)

DESCRIPTION

 

Citation preview

  • 1. Database Connectivityusing ADODB

2. Visual Basic 6 ADO Visual Basic 6 obsoletes the previously useddatabase access technology provided by Jet This provides a new one known as ADO or ActiveData Objects This technology allows users to access dataeasily from many existing databases like Oracleor MS SQL Server ADO is quite simple and allows programmers toprovide flexible database front ends 3. Connection Object This object represents an open connection to thedata source This connection can be a local connection or canbe across a network Key Properties and MethodsPropertyMethods ConnectionString Close Provider Open ConnectionTimeout CommandTimeout CursorLocation Mode 4. Command Object A command object specifies a specific methodyou intend to execute on or against the datasource accessed by an open connection Key Properties and Methods Property Methods Key Properties and Execute Methods CommandText CommandType 5. Recordset Object The RecordSet object represents a complete setof records from an underlying base table in thedatabase RecordSet object references only one record at atime as the current record Key Properties and Methods MethodsProperty CursorLocation AddNew CursorType Close and Open EOF and BOFMoveNext Fields MoveFirst RecordCountMoveLastMovePrevious 6. Putting These altogether Define and open a Connection to a data source Decide what data you need from the data sourceand define Command objects that will retrieve thisdata. Retrieve the data you require by executing thecommand objects and manipulate the data usingRecordSet objects. 7. Database ConnectivitySteps Make a VB application that can be used to connect to database 8. Go to components 9. Choose Microsoft ADO Data Control 6.0(OLEDB) 10. Component is added 11. Click on Adodc and go to its properties 12. Click on Build 13. Select Microsoft Jet 4.0 OLE DB Provider and next 14. Select database and test the connection 15. From here copy connection string and click ok 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;DataSource=C:Documents andSettingsAdministratorDesktopEmployee.mdb"con.Openrs.Open "select * from employee", con,adOpenDynamic, adLockOptimisticcmd.ActiveConnection = con 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. How to use Flex Grid in VB Go to components 19. Choose Microsoft FlexGrid Control 6.0 from components 20. Select flexgrid from toolbox and drop it in form 21. Select Data tool from tool box and drop it in form 22. Select DataSource property of FlexGrid 23. Choose DatabaseName from Data tool properties 24. Choose your database which you want to use 25. Choose Recordset property of Data tool 26. Your selected recordset will be shown in flexgrid 27. How to use data grid in VB Go to components 28. Select Microsoft DataGrid Control 6.0(OLEDB) 29. Select data grid from tool box and drop in form 30. Go to Adodc properties 31. Select Microsoft Jet 4.0 ILE Db Provider 32. Select database name 33. Test the connection 34. Go to RecordSource select CommandType as 2- adCmdTable and Table 35. Select DataSource from data grid properties 36. Your data grid is working 37. References http://www.w3schools.com http://www.codeproject.com http://msdn.microsoft.com