You are on page 1of 9

Q91. What actions trigger the initialize and the terminate event of the object ? Ans.

The Class_initialize event is triggered when an object is created and the Class_initialize event occurs when an object goes out of scope or is terminated with Set ObjectName = Nothing. These event procedures are useful for doing any setup work for making sure that the memory allocated for an object is released. Public Sub Class_Initialize() Create the collection object Set mProducts = New Collection End Sub Public Sub Class_Terminate() Remove the collection from memory Set mProducts = Nothing End Sub

Q92. For which type(s) of Record Set is a Find valid(FindFirst, FindNext, FindLast, FindPrevious)? What types of data can be searched for with a Find? Ans: You can search for a particular value in any field in a dynaset or snapshot. For example, you could request a certain name, account number, phone number, book title field stored in the Database and bound to one of your controls. Use the FindFirst, FindNext, FindLast, FindPrevious to locate any data.

Q93. What do you mean by error handling, debugging. Error handling is an essential procedure in Visual Basic programming because it can help make the program error-free. An error-free program can run smoothly and efficiently, and the user does not have to face all sorts of problems such as program crash or system hang. Errors often occur due to incorrect input from the user. For example, the user might make the mistake of attempting to ask the computer to divide a number by zero which will definitely cause system error. Therefore a good programmer should be more alert to the parts of program that could trigger errors and should write errors handling code to help the user in managing the errors. Writing errors handling code should be considered a good

practice for Visual Basic programmers, so do try to finish a program fast by omitting the errors handling code. Debugging Visual Basic provides many tools to help analyze how your code operates. These debugging tools are particularly useful in locating the source of errors, or bugs. You can also use them to help you learn how code written by other people works. When you write your code, you will never be able to create code that works first time round perfectly. Or if you do, if you change another section of code, this may well affect code you have already written which then does not work.

Q94. When would an On Error statement be used? We must place an On Error statement at the beginning of the any procedure where error might occur, such as before opening sequential file for input. An on error statement will trap the error and it will direct the execution control to the error trap level. Actually, there are four different statements that we can use when error occurs.

(i)

Resume Next: It tells VB that if an error occurs, the program should simply skip to the next line of the code and bypass the line where the error has occurred.

Example:

Private sub cmdDelete_Click( ) on Error Resume Next Stop Kill txtFile if err.Number MsgBox " such a file doesn't exit " Endif End Sub

'Kill statement delete the specified file in the textbox

(ii)

Resume (Label Name ):This statement is used , if you want to transfer execution control to some different location or you just want to ignore the error

Example: private sub cmdOpen_Click( ) OnError GoTo ErrorTrap set db = OpenDatabase("C:\emp.mdb") Normal Exit: Exit Sub Error Trap: Msgbox " Failed to open the file " Resume NormalExit End sub

(iii)

Resume: When Error occurs and if you want to give the user a chance to fix the error , the above statement is used.

Example:

If we try to access a floppy without putting it into the disk drive , our application may ask us to insert it and then continue with the execution again.

private sub cmdResume_Click( ) On Error Go To ErrorTrap MsgBox" Length of the file is " & FileLen( txtFile ) Normal Exit: Exit sub Error Trap: If err.Number then If MsgBox (" Floppy drive error try again ") = vbYes then Resume Endif End Sub

(iv)

The errObject: Every time an error occurs VB creates an object, which contain error information. This error object can be used to retrieve the information about the type of error which has occurred.

Q95. What is cursor? Explain different types of Cursors. A cursor's type, in ADO terminology, indicates some facts about how it behaves, what you can and can't do with it, and how thrifty or wasteful it is with system resources. You can set a Recordset's cursor type by setting its CursorType just before you open it, The following sections discuss the four cursor types available from the ADO Cursor library. 1. Forward-Only Cursors 2. Static Cursors 3. Keyset Cursors 4. Dynamic Cursors Forward-Only Cursors A Forward-Only cursor behaves a lot like sequential file access: It only furnishes one record at a time, and then only in strict order from the beginning to the end of the rowset. In other words, we can't use a Forward-Only cursor to skip around in a Recordset's rows. we can only move forward one record at a time until you reach the EOF condition at the end of the Recordset. If we attempt to use any other Recordset navigation method besides MoveNext, we will generate a runtime error. A Forward-Only cursor is the default ADO cursor, because it consumes the least resources of all cursor types. Static Cursors Static cursors are less economical than Forward-Only cursors, but they allow greater flexibility of movement through the rowset. A Static cursor supports navigation in all directions, and it enables us to make repeat visits to the same record during the same session. The biggest drawback to a Static cursor is the fact that its rowset doesn't get updated with concurrent changes made by other users. If User A opens a Static cursor on a set of records and User B makes changes to the records during User A's session, for example, User A will not see the changes made by User B. To see User B's changes, User A's Static cursor would have to close and then be reopened. The user can make changes to the Static cursor's Recordset, but (once again) the user cannot see changes made by others during the time that the cursor is

open. This includes additions and deletions to the records as well as editing changes to individual records. Keyset Cursors Keyset-type cursors have the same freedom of movement in any direction as Static cursors. In addition, Keyset cursors can immediately see changes to existing records made by other users. However, additions and deletions made by other users are not visible to a Keyset-type cursor. Dynamic Cursors Dynamic cursors have all the flexibility and visibility of Keyset-type cursors with an extra enhancement: Additions and deletions made by other users are visible to a Dynamic cursor. Dynamic cursors are, however, the biggest resource hogs, so you should be very sure that you absolutely need a Dynamic cursor before deciding to use one. Q95(a) Explain different types of cursor location.
Cursor location is important, because you need to manage where cursors get their resources from. A cursor can be implemented at one of two general locations: Client-side cursors implement the cursor with resources on the local workstation (the "client machine"). Server-side cursors implement the cursor with resources on the server machine

Client-Side Cursors A client-side cursor uses local machine resources to implement a cursor and its set of records. The advantages of client-side cursors are as follows: Because they run locally, they provide better performance when their result sets are a reasonable size. Client-side cursors generally provide better scalability, because their performance depends on each client, and not on the server. Therefore, client-side servers place less of a growing demand on the server as the number of a system's users increases.

The disadvantages of client-side cursors are as follows: When the rowset returned with the cursor is very large, the local workstation's resources may be "swamped" by the need to handle the high volume. Because a client-side cursor must bring all the data for its rowset over the network, larger result sets can increase network traffic.

Server-Side Cursors A server-side cursor uses server resources to implement a cursor and its set of records. The advantages of server-side cursors are as follows: Local workstation resources are never "swamped" by unexpectedly large rowsets. Because a server-side cursor does not transfer all the data in the rowset to the workstation, there is less network traffic with large rowsets when they are opened and less delay in opening them.

The disadvantages of server-side cursors are as follows: For smaller rowsets with a lot of activity performed by the application, server-side cursors do not perform as well, because each request to move the cursor and each response must travel over the network. It would be better to just transfer the smaller rowsets to the client to start with. As users are added to the system, the server receives a greater and greater resource demand as more and more concurrent users open server-side cursors. Server-side cursors therefore typically provide less scalability than client-side cursors.

Q96. Explain different debugging tools. There are several debugging tools available for use in Visual Basic. Debugging tools are designed to help you for: 1. Finding logic and run time errors 2. Observing the behaviour of code that has no errors. The tools include Breakpoints: Definds a line in the code window where Visual Basic suspends execution of the application. watch window: Displays the value of selected expression. Immediate window: Allows you to execute code or query values while the application is in break mode. Step into: Executes the next executable line of code in the application and steps into procedures. Step over: Executes the next executable line of code in the application without stepping into procedures. Step out: Executes the remainder of the current procedure and breaks at the next line in the calling procedure. Local window: Displays the current value of local variables. Call stack: While in break mode presents a dialogue box that shows all procedures that have been called but not yet run to completion.

Q97. Explain different types of Lock in ADO. To support data integrity and avoid conflicts between users trying to update the same data at the same time (concurrency conflicts), most modern DBMSs support some sort of locking scheme. ADO recognizes four different types of data locking, represented by four enumerated constants:

adLockReadOnly (default) - When a recordset is opened, the user may not make any changes to the data. This ensures that concurrency conflicts with other users are avoided. adLockPessimistic - Provider guarantees that a record under editing will be able to have its changes saved. This is usually accomplished by locking the record as soon as it becomes the current record under a cursor. The lock is released when the cursor moves off the record or the recordset is closed.

adLockOptimistic - Provider does not guarantee that a record under editing will have its changes saved. Provider locks the record only during the update process. adLockBatchOptimistic - For server-side cursors, this option guarantees that all cursor options will be supported in the most efficient way.

You can set the type of lock on the data underlying a Recordset by setting the Recordset's LockType property to one of the previously mentioned values before you open it.

Q98. Explain how BOF and EOF properties are set and how they might be used in a project. Ans: 1. Two handy properties of the record set are BOF (beginning of file) and EOF (end of file). The BOF property is automatically set to true when the record pointer is before the first record in the record set. This condition happens when first record is current and the user choose MovePrevious. The BOF property is also true if the record set is empty 2. The EOF property is similar to BOF; it is true when the record pointer moves beyond the last record in the record set and when the record set is empty. 3. When you are doing your own navigation in code, you need to check for BOF and EOF so that run time errors do not occur. If the user clicks MoveNext when on the last record, what do you to do? Have the program cancel with a run time error? Display a message? Wrap around the first record? Keep the record pointer to last record? 4. In the following example, we will wrap-around method. If the user clicks on the MoveNext button from the end of the table, the first record becomes active record. Private Sub cmdNext_Click() , Move to Next record datBooks.Recordset.MoveNext If datBooks.Recordset.EOF Then datBooks.Recordset.MoveFirst End If End Sub

Q99. What are database components? There are mainly three kinds of database components in UDA architecture. They are 1) Data provider: It is a control or object that provides data for use with another control or program. It makes connectivity much easier by hiding

most of the implementation from the user so that the user can concentrate of on utilising data. 2) Service components: Service component perform the task of processing the data and transmitting it to a data consumer. 3) Data consumers: It is an application that retrieve data from a service component. Q100. What are the steps needed to add a new record to database? Ans:
1. Private Sub Add_Click() 2. Adodc1.Refresh 3. Adodc1.Recordset.AddNew 4. Adodc1.Recordset.Fields("Au_Id") = Text1.Text 5. Adodc1.Recordset.Fields("Author") = Text2.Text 6. Adodc1.Recordset.Fields("YearBorn") = Text3.Text 7. Adodc1.Recordset.Update 8. MsgBox "Data Added" 9. End Sub

Q101. What are the steps needed to delete a record from database? Ans: 1. The delete method deletes current record. The user should display the record to delete and click a Delete command button or menu choice. 2. When a record is deleted, the current record is no longer valid. Therefore, a delete method must be followed by MoveNext method. With datBooks.Recordset .Delete .MoveNext End With 3. But what if the record being deleted is the last record in the table? 4. Remember that if the navigation buttons are used to navigate, moving beyond EOF just resets the current record to the last record.

Q102. What steps are needed to change the data in a database? Ans: The record set object has an Update method, which you can use to save any changes in the data. Most of the time, updating is automatically executes the Update method any time the user clicks one of the navigation buttons or one the Move methods executes.

You might also like