Você está na página 1de 28

Summer 09 Q.1. Attempt any four of the following a) Enlist any four drawbacks of previous language. Ans. 1. 2. 3. 4. 5. 6. 7. 8. 9.

VB does not support exception handling. VB DLL does not support side-by-side execution The VB support OOP concepts, but not support fully. It does not provide multithreading mechanism. It is interpreter based language. It is not a safe language. It is not good for web applications, distributed applications. The Applications doveloped in vb are working only on Windows OS. The slower speed for execution

b) What are objects & properties? How are they related to each other? Ans. Objects:- Objects are the basic run-time entities in an object-oriented system. Programming problem is analyzed in terms of objects and nature of communication between them. When a program is executed, objects interact with each other by sending messages. Different objects can also interact with each other without knowing the details of their data or code. Properties:- Properties are members of the class. Properties represent information that an object contains.Properties are members that can be implemented in two different ways. In its simplest implementation,a property is just a public variable, as in: Public Class CPerson Public Age As Integer End Class The "proper" object-oriented way to implement a property is to use a Private data member along with a special pair of function members. The Private data member holds the property value; the pair of function members, called accessors, are used to get and set the property value. Private myAge As Integer Property Age( ) As Integer Get Age = myAge
Compiled By Prof. Vaibhav Vasani

End Get Set(ByVal Value As Integer) ' Some validation If Value < 0 Then MsgBox("Age cannot be negative.") Else myAge = Value End If End Set End Property HOW THEY ARE RELATED TO EACH OTHER? c) Draw & write the steps in processing a FOR/NEXT loop. Ans. FOR NEXT Loop : For loops enable us to execute a series of expressions multiple numbers of times. The For loop in VB .NET needs a loop index which counts the number of loop iterations as the loop executes. Syntax :For var=[startValue] To [endValue] [Step] [loopBody] Next [var] var : The counter for the loop to repeat the steps. starValue : The starting value assign to counter variable . endValue : When the counter variable reach end value the Loop will stop . loopBody : The source code between loop body. Example on For loop Module Module1 Sub Main() Dim d As Integer For d = 0 To 2
Compiled By Prof. Vaibhav Vasani

System.Console.WriteLine("In the For Loop") Next d End Sub End Module Every loop consists of the following three steps: (1) The loop termination decision - determines when (under what condition) the loop will be terminated (stopped). It is essential that some provision in the program be made for the loop to stop; otherwise, the computer would continue to execute the loop indefinitely - a loop that doesn't stop is called an endless loop or infinite loop; when a program gets stuck in an endless loop, programmers say that the program is "looping". (2) The body of the loop - the step or steps of the algorithm that are repeated within the loop. This may be only one action, or it may include almost all of the program statements. Important note: some action must occur within the body of the loop that will affect the loop termination decision at some point. (3) Transfer back to the beginning of the loop - returns control to the top of the loop so that a new repetition (iteration) can begin.

Flowchart for FOR NEXT LOOP:-

Compiled By Prof. Vaibhav Vasani

d) Explain the purpose of data adapters & datasets. Ans. Data Adapters:-Data adapters are an integral part of ADO.NET managed providers, which are the set of objects used to communicate between a data source and a dataset. (In addition to adapters, managed providers include connection objects, data reader objects, and command objects.) Adapters are used to exchange data between a data source and a dataset. A data adapter needs an open connection to a data source to read and write data. Generally, each data adapter exchanges data between a single datasource table and a single DataTable object in the dataset. Datasets:- A Dataset is a in memory representation of a collection of Database objects including tables of a relational database scheme. The dataset contains a collection of Tables, Relations, constraints etc., It can be used for manipulating the data remotely and finally updating the database with the modified data. This way it enables disconnected means of working with data. This improves performance in terms of reducing the number of times a database is accessed for data manipulations. The dataset contains all the objects as a Collection of objects. For example it contains the Database Tables as DataTable objects. The data from the database is filled into the dataset by using the DataAdapter.

e:-Difference between client & server for web application. f:-Explain how session objects can be used enable & disable a session. Q2.attempt any 3 1. Explain any 2 components of .net framework 2. What is the purpose of the text property of a button and text property of a form? 3. Explain the use of fill method with the help of example 4. Explain the following web form controls: 1. HTML server control 2. Web server control Q: 3 Attempt any 3: a)Explain any 4 relational operators with example. Ans.

Compiled By Prof. Vaibhav Vasani

The relational operator will take two values and compare them, it will then return a boolean value depending on the relation between the values. There's a total of 6 relational operators which you can use in VB.NET, they are: Equals to, Not equals to, Greater then, Less then, Greater then or equals to and less then or equals to.

i) Equals to: Writes "=" This relational operator checks if the two values are the same, if they are, it will return True. Here's some examples:

[highlight=VB.NET] MessageBox.Show(False = True) MessageBox.Show(7 = 7) MessageBox.Show(8 = 8.000) [/highlight]

These three message boxes will show False, True and True. False and True is not equals to each other so that one returns False. In the second one both the values are 7 so that one will return True. In the last one the both values are not exactly the same values but the values have the same size so that one will also return True. Remember that you also use the equals sign for setting values of variables. ii) Not equals to: Writes "<>"

This is the opposite of the Equals to operator. The Not equals to operator will return true if the values it compares are not the same. If we're using the Not logical operator together with the equals to relational operator we can create a Not equals to operator in another way. Anyway, here's a few example of the normal Not equals to operator: [highlight=VB.NET] MessageBox.Show(1 <> 3)
Compiled By Prof. Vaibhav Vasani

MessageBox.Show(-5 <> -5) MessageBox.Show("text" <> "another text") [/highlight] 1 and 3 are not the same so therefor the first messagebox will show "True". The second one's values is the same so that one will return False. In the last one we use two string instead, the both strings are not the same so the third messagebox will show "True". iii) Greater then and Less then: Writes ">" and "<" The Greater then and Less then operators will compare the size of the two values. If you use them on non-numeric values you get strange results so try to avoid using them together with non-numeric values. Here comes some example on how to use them with numeric values: [highlight=VB.NET] MessageBox.Show(25 > 3) MessageBox.Show(5 < 42) MessageBox.Show(12 > 12) [/highlight] Since 25 is greater then 3 the first will return True. The second one is also True since 5 is less then 42. The last one is a little bit trickier, but 12 is not greater then 12, therefor the last one will return False. iv) Greater then or equals to and Less then or equals to: Writes ">=" and "<="

The Greater then or equals to is the same as Greater then and Less then or equals to is the same as Less then, both with one exception. If the two values are the same Greater then or equals to and Less then or equals to will return True which is not the case for Greater then and Less then which will return false. Here comes some example, these example uses the same values as in the last subject about Greater then and Less then: [highlight=VB.NET] MessageBox.Show(25 >= 3) MessageBox.Show(5 <= 42)
Compiled By Prof. Vaibhav Vasani

MessageBox.Show(12 >= 12) [/highlight]

In the first and second example we will get the same result as before. But in the last example we will get a difference. 12 is not greater then 12 but 12 is equals to 12, therefor Greater then or equals to will return True here were Greater then returned False with the same values. b)What is an advantage of transferring data as XML, rather than a proprietary format, such as Access or SQL server? Ans. An XML database has several advantages over key-value, relational, and object-oriented databases: 1. XML data is dropped straight into the database; it does not need to be manipulated or extracted from a document in order to be stored. 2. When inserted into the database, most (in Berkeley DB XML, all) aspects of an XML document, including white space, are maintained exactly. 3. Queries return XML documents or fragments, which means that the hierarchical structure of XML information is maintained. For the XML community, XML databases solve two specific problems: 1. It is prohibitively costly (in terms of memory and processor requirements) to build in-memory trees of very large documents and then query those trees. Anyone using XSLT or any DOM-aware application to process very large documents will run into this problem; a 100 megabyte file may require as much as 1.2 gigs of available memory. Berkeley DB XML can easily hold gigabytes of XML data, making it all easily addressable via XPath queries. 2. Accessing one part of a document, la XInclude, usually requires parsing an entire XML document before the requested fragment can be returned. For small XML documents, this is not a problem, but for large documents transmitted over a network, it's a waste of bandwidth and processor time. An XML database like Berkeley DB XML can find arbitrary sections of a stored XML document without any parsing. Wrapped in a web service, Berkeley DB XML could easily be programmed to provide "remote XInclude" functions via HTTP, which means that a language like XSLT, using its document() call, could easily fetch chunks of XML from a network at minimal cost in bandwidth and processing time.

Compiled By Prof. Vaibhav Vasani

In general, XML databases allow programmers with XML data to quickly create data stores with that data, with the minimum of programming time required, and eliminate the need to convert XML into other data structures. c)What is data binding? Explain 2 forms of data binding in ADO.NET Ans. DataBinding 1. Data Binding is binding controls to data from databases. 2. With data binding we can bind a control to a particular column in a table from the database or we can bind the whole table to the data grid. 3. Data binding provides simple, convenient, and powerful way to create a read/write link between the controls on a form and the data in their application. 4. Working with Data Binding in ASP.NET is slightly different to working with it in VB .NET 5. Generally, Datasets don't maintain a current record that is displayed in bound controls. 6. In VB .NET, the BindingContext object handles that and it lets us set the record bound control display. 7. In ASP.NET, there is no BindingContext object to handle that. 8. In ASP.NET, we use a DataView to let the user select which record should be displayed in bound controls. 9. We bind the controls using data view and use the RowFilter property of the data view to select the record we want the bound control to display. 10. Simply said, in VB .NET we use the Dataset to bind records to the bound control and in ASP.NET we use a DataView. d)Explain update method with example Ans : 1. The Update() method can submit DataSet changes back to the data source. 2. It uses the statements in the DeleteCommand, InsertCommand and UpdateCommand objects to attempt to update the data source with records that have been deleted, inserted or updated in the DataSet. 3. Each row is updated individually and not as a part of a batch process. 4. Furthermore, the order in which the rows are processed is determined by the indexes on the DataTable and not by the update type. Q 4.Attempt any 4 1. Describe how to convert VB application into VB.NET application with example.
Compiled By Prof. Vaibhav Vasani

ANS. There are lots of difference in between VB6 and VB.NET and to help user upgrade VB6 projects into VB.NET, Microsoft created the visual basic Upgrade Wizard. This wizard is automatically opens whenever, user try to open a VB6 project in Vb.NET IDE. The upgrade wizard will convert the Visual Basic 6.0 application into the equivalent Visual Basic .NET application. The Visual Basic forms are converted into the equivalent Windows Forms. All the controls on the form are converted into their equivalent Windows controls. The upgrade wizard makes all the necessary syntax changes for converting the code into Visual Basic .NET. However, the upgrade wizard does not perform upgrades on Visual Basic 6.0 features such as DDE, OLE, DAO and RDO data bindings. The upgrade wizard produces an upgrade report. This report gives a status of the upgrade process, listing all the features that were upgraded by the wizard and all those features that were not upgraded. STEPS TO CONVERT VB6 PROGRAM INTO VB.NET: You can create a simple application in VB6 and run it in VB6 IDE Now, you try to open the application, made in VB6, in VB.NET IDE. A wizard will pop-up on the screen If you want to proceed, click NEXT button. Now wizard will ask for the type (i.e. either a dll or exe) you want to upgrade into, your application. After selecting any one type click NEXT. Again you will be asked for the location where you want to store your upgraded application, provide the appropriate location and click NEXT. Then it will take 1-2 minutes to upgrade your application in VB.NET. And then finally you will get your project in solution explorer of VB.NET.

EXAMPLE: Code in VB6 Private Sub Form_Load() Dim a, b, c As Integer a=10 b=20
Compiled By Prof. Vaibhav Vasani

c=a+b Text1.Text = c End Sub The above VB6 code when upgrade to Vb.NET looks something like this: Option Strict Off Option Explicit On Friend Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs)Handles MyBase.Load Dim a, b As Object Dim c As Short UPGRADE_WARNING:. a=10 UPGRADE_WARNING:. b=20 UPGRADE_WARNING:. UPGRADE_WARNING:. c=a+b Text1.Text=CStr(c) End Sub End Class 2.Write ASP.NET code to display all files form all folders of C: Ans. Partial Class _Default Inherits System.Web.UI.Page
Compiled By Prof. Vaibhav Vasani

Protected Sub Button1_Click(ByVal sender System.EventArgs) Handles Button1.Click

As

Object,

ByVal

As

Dim fso = Server.CreateObject("Scripting.FileSystemObject") Dim j, k Dim a = "d:" Dim d = fso.getDrive(a) Dim fd = fso.getfolder(d) For Each j In fd.subfolders Response.Write("<b><u>" & "+" & j.name & "</u></b>") Response.Write("<br/>") Response.Write("<br/>") For Each k In fd.files Response.Write(" - " & k.name) Response.Write("<br/>") Next Response.Write("<br/>") Response.Write("<br/>") Next End Sub End Class OUTPUT:

Compiled By Prof. Vaibhav Vasani

3.Describe the steps necessary to display position and record for single record. 4.What 2 files make up a web form? What is the purpose of each file? 5.create a web page for entering the new customer Information. Validate that all fields contain Information. ANS. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <h1>New Customer Information</h1> <div style="table-layout: fixed"> <asp:Label ID="Label1" absolute; top: 208px" runat="server" Style="left: 330px; position:

Text="EMAIL"></asp:Label> &nbsp;&nbsp; <asp:Label ID="Label4" absolute; top: 358px" runat="server" Style="left: 335px; position:

Text="PASSWORD"></asp:Label>

Compiled By Prof. Vaibhav Vasani

<asp:TextBox ID="TextBox1" runat="server" Style="left: 447px; position: absolute; top: 135px"></asp:TextBox> &nbsp; <asp:TextBox ID="TextBox3" runat="server" Style="left: 454px; position: absolute; top: 280px"></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server" Style="left: 454px; position: absolute; top: 353px" TextMode="Password"></asp:TextBox> <asp:TextBox ID="TextBox5" runat="server" Style="left: 462px; position: absolute; top: 429px" TextMode="Password"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server" Style="left: 449px; position: absolute; top: 205px"></asp:TextBox> <asp:Label ID="Label3" absolute; top: 286px" runat="server" Style="left: 334px; position:

Text="USERNAME"></asp:Label> <asp:Label ID="Label2" absolute; top: 132px" runat="server" Style="left: 330px; position:

Text="NAME"></asp:Label> <asp:Label ID="Label5" absolute; top: 436px" runat="server" Style="left: 349px; position:

Text="CONFIRM"></asp:Label> <asp:Button ID="Button1" runat="server" Style="left: 441px; position: absolute; top: 508px" Text="SUBMIT" />
Compiled By Prof. Vaibhav Vasani

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate ="Textbox1" Text="You must enter the name" ErrorMessage="RequiredFieldValidator" style="left: 655px; position: absolute; top: 130px"></asp:RequiredFieldValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate ="Textbox2" Text="You must enter the user email" ErrorMessage="RequiredFieldValidator" Style="left: 648px; 200px"></asp:RequiredFieldValidator> position: absolute; top:

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate ="Textbox3" Text="You must enter the username" ErrorMessage="RequiredFieldValidator" Style="left: 653px; 277px"></asp:RequiredFieldValidator> &nbsp; <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate ="Textbox5" Text="You must enter the same password to confirm" ErrorMessage="RequiredFieldValidator" Style="left: 638px; 424px"></asp:RequiredFieldValidator> &nbsp; <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate ="Textbox4" Text="You must enter the Password" ErrorMessage="RequiredFieldValidator" Style="left: 646px; 352px"></asp:RequiredFieldValidator> </div> </body> </html> OUTPUT:</form> position: absolute; top: position: absolute; top: position: absolute; top:

Compiled By Prof. Vaibhav Vasani

6.How database connectivity is achieved in asp.net? write the code to display name and salary of employee from employee database Ans. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <%@ Import Namespace ="System.data.oledb" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <script runat ="server" > Protected Sub Page_Load(ByVal System.EventArgs) Handles Me.Load sender As Object, ByVal e As New

Dim con As OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Employee.mdb;") Dim cmd As New OleDbCommand("select * from emp", con)
Compiled By Prof. Vaibhav Vasani

con.Open() DataGrid1.DataSource = cmd.ExecuteReader DataGrid1.DataBind() con.Close()

End Sub </script> <body> <form id="form1" runat="server"> <div> <asp:DataGrid ID="DataGrid1" runat="server"> </asp:DataGrid></div> </form> </body> </html> <asp:datagrid runat="server"></asp:datagrid> OUTPUT:-

Compiled By Prof. Vaibhav Vasani

Q.5. Attempt Any Three of the following : a)Describe the component content linker with example. The Content Linking component manages a list of URLs so that you can treat the pages in your website like the pages in a book .The Content Linking component can be used to automatically generate and update tables of contents and navigational links to previous and subsequent Web pages .This is ideal for application such as online newspaper and forum message listings. The Content Linker has two parts: 1. The index file(ListFile) : An ASCII text file that holds a list of .asp pages, in the order that they should be presented to the viewer. The index file can easily be changed to add new pages, revise the order of page or substitute newer pages for older pages. 2. The ASP pages : Each .asp file contains two parts. The first part consist of the normal content of the page, such as the and graphics. The second part is the ASP code that uses the Content Linker to give the user options for moving through the list of pages. These options are typically hyperlinks for the Next Page, Previous Page, First Page and Last Page. The Content Linking component creates a NextLink object that manages a list of URLs. Syntax : Set NextLink=Server.CreateObject(MSWC.NextLink) The Content Linking component uses a content linking text file that contains the relative URLs of each page and the text to display as the hyperlink for that page. Once you instantiate the component on a page and tell it where to find the content linking text file, to the previous or next page or directly to any other page in the list. If you need to insert another page into the list or change the order they are displayed in, you just edit the content linking text file. The links in each page are automatically updated. We use the content linking component mainly to save effort when creating sample file menus on the Web-site. The content linking component depends on an external file kept on the server for its list of navigable content. A index file will be text file that looks like as follows :

Compiled By Prof. Vaibhav Vasani

HTMLPage1.htm HTMLPage2.htm HTMLPage3.htm

HTMLpage1 HTMLpage2 HTMLpage3

Intro Variables Procedures

Each line in the above file includes three things : 1. The relative UR of the content page. 2. The display text. 3. A comment describing the content. Each of three line sections must be separated by a tab character. Methods : The content link component has no properties, only the following methods : Method Description Syntax GetListCount This Method returns the ObjContent.GetListCount(c number of topics(URLs and ontentFile Name) descriptions) in a Content Linking list file. The GetListIndex method ObjContent.GetListIndex returns an integer, which is (contentFile Name) the order of the current page in the content list. This method returns description of the next the ObjContent.GetNextDescri ption (contentFile Name) ObjContent.GetNextURL(c ontentFile Name) ObjContent.GetNthDescrip tion (contentFile Name,itemIndex) ObjContent.GetNthURL(co ntentFile Name,itemIndex) ObjContent.GetPreviousDe scription

GetListIndex

GetNextDescriptio n GetNextURL GetNthDescriptio n

GetNthURL GetPreviousDescri ption


Compiled By Prof. Vaibhav Vasani

(contentFile Name) GetPreviousURL ObjContent.GetPreviousUR L (contentFile Name)

Example : To Create a simple content linking component. 1. Open a new web site. 2. Select add new item by right click the main project in solution explorer or by using website menu and text file. 3. Write following code : 4. Add the following code in default.aspx file.

HTMLPage1.htm HTMLPage2.htm HTMLPage3.htm

TextFile.txt HTMLpage1 HTMLpage2 HTMLpage3

Intro Variables Procedures AspCompat="true"

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <ul> <% Dim nl As New Server.CreateObiect("MSWC.NextLink") Dim count = nl.getlistcount("TextFile.txt") Dim i For i = 1 To count%> <a href="<%=nl.getNthUrl("TextFile",i)%>"> <%=nl.getNthDescription("TextFile",i) %> </a> <% Next%>
Compiled By Prof. Vaibhav Vasani

</ul> </div> </form> </body> </html> b)Write short note on ASP transactions. Ans. A transaction is an automatic unit of work that either fails or succeeds as a whole. Transactions are always executed as a whole. A transaction symbolizes code or a set of components or procedures which must be executed as a unit. In ASP and ADO Connection Object is used to create open connection to a data source rather than ADO.net. If you want to access a database multiple times, you should estabilished a connection using the connection object. You can also make a connection to a database by passing a connection string via a command or Record set object .However, This type of connection is only good for one specific, single query. Syntax: set objConnection=Server.CreateObject(ADODB.connection) There are lots of properties and methods of connection object in ASP. But here we are interest only in properties and methods that are related with transactions, these are as follows: Properties: Property ConnectionString IsolationLevel Methods: Methods BeginTrans Cancel Close CommitTrans RollbackTrans

Description Sets or return the details used to create a connection to a data store . Sets or return the isolation level Description Begins a new transaction. Cancel an execution. Closes a Connection. Saves any changes and ends the current transaction. Cancels any changes in the current transaction and ends the transaction.

Events: An event is a sub routine that can be called automatically after a specific operation has occurred.
Compiled By Prof. Vaibhav Vasani

Events BeginTransComplete

Description Event can be fired after a BeginTrans call is Completed. CommitTransComplete Event can be fired after a CommitTrans call is Completed. RollbackTransComplete Event can be fired after a RollbackTrans call is Completed. c)Explain synchronization of threads in multithreading. Ans. There may be a situation when two threads working with same data and you might not want the second thread to work with that data until the first thread is finished with it. So In this situation synchronization is necessary you can achieve synchronization by, SyncLock stamen and Join method : Imports System.Threading Imports System.Data Imports System.Text Module Module1 Dim i As Integer Dim txt As New StringBuilder Sub Main() Dim first As New Thread(AddressOf fun1) Dim second As New Thread(AddressOf fun2) first.Start() second.Start() first.Join() second.Join() Console.WriteLine("Text is {0}{1}", vbCrLf, txt.ToString) Console.Read() End Sub Public Sub fun1() For i = 1 To 10 Thread.Sleep(1) txt.Append(i.ToString() + " ") Next End Sub Public Sub fun2() For i = 11 To 20 Thread.Sleep(1) txt.Append(i.ToString() + " ") Next End Sub
Compiled By Prof. Vaibhav Vasani

End Module Output: 11 1 12 13 2 14 5 3 16 17 4 20 7 9 8 19 15 18 6 19 The final text is unorderd sequence of numbers. To avoid threads interfering with each others result thread should lock the shared object before it starts appending the numbers and release the lock when it is done. SyncLock gains an exclusive lock to an object reference that is passed to it By gaining this exclusive lock you can ensure that multiple threads are not accessing shared data or that the code is executing on multiple threads. We can change the above code to provide thelocking functionality : Imports System.Threading Imports System.Text.StringBuilder Imports System.Data Imports System.Text Module Module1 Dim i As Integer Dim txt As New StringBuilder Sub Main() Dim first As New Thread(AddressOf fun1) Dim second As New Thread(AddressOf fun2) first.Start() second.Start() first.Join() second.Join() Console.WriteLine("Text is {0}{1}", vbCrLf, txt.ToString) Console.Read() End Sub Public Sub fun1() SyncLock txt For i = 1 To 10 Thread.Sleep(10) txt.Append(i.ToString() + " ") Next End SyncLock End Sub Public Sub fun2() SyncLock txt For i = 11 To 20 Thread.Sleep(2) txt.Append(i.ToString() + " ") Next End SyncLock End Sub End Module
Compiled By Prof. Vaibhav Vasani

Output : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 d)Explain data table and data row with example in ASP.Net Ans. DataTable Object: The DataTable is a central object in the ADO.NET library. ADataTable has a collection of rows and arrows represented by the Rows property and Columns property. A DataTable can be build by programming, consisting of records by adding DataColumns to the columns collection and DataRows to the collection. Other objects that use the DataTable include the DataSet and the DataView. When accessing DataTable objects, they are conditionally case sensitive. For example, if one DataTable is named mytable and another is named Mytable, a string used to search for one of the tables is regarded as case sensitive. However, if mytable exists and Mytable does not, the search string is regarded as case insensitive. Creating a DataTable You can add it to a DataTable object by using the appropriate dataTable constructor. You can add it to the Dataset by using the Add method to add it to the DataTable objects Tables collection. Dim tb as DataTable = New DataTable(Table1) To add rows to a DataTAble, you must first use the NewRow method to return a new DataRow object. The NewRow method returns a row with the scheme of the DataTable. Adding data to datatable (DataRow) : After you create a DataTable and define its structure using columns and constraints, you can add new rows of data to the table. To add a new row, declare a nw varible as type DataRow. A new DataRow object is returned when you call the NewRow method. The DataTable then creates the DataRow object based on the the struccure of the table, as defined by the DataColumnCollection. Dim row as DataRow=tb.NewRow() Example : row(colname) = value tb.Rows.Add(row) Adding row to table

Compiled By Prof. Vaibhav Vasani

Q6 Attempt any Three of the following: (a) Explian any four methods of response object of ASP.Net ANS: There are 8 methods of ASP.Net are: 1.Write 2.Redirect 3.Flush 4.End 5.Clear 6.BinaryWrite 7.AppendToLog 8.AddHeader 1.Response.Write method: The response.write method can be used to write a string to Http output.It is very useful and mostly used to write out the contents of the variable.You can also use <%---%> in HTMl if you dont want to write Response.Write. Syntax: Response.Write(variant) The variant argument is the data to be written as a string. Example:Writing on a browser: <% Response.Write(hello everyone) %> 2.Resonse.Redirect method:

Compiled By Prof. Vaibhav Vasani

Resonse.Redirect method can be used to redirect the user to another URL.This can be useful after a process has taken place and you want the user redirect to another page. Syntax: Response.Redirect(URL) Example: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Q9.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <script runat=server> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Redirect(TextBox1.Text) End Sub </script> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="enter url"></asp:Label> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <asp:TextBox ID="TextBox1" runat="server" Width="350px"></asp:TextBox><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <asp:Button ID="Button1" runat="server" Text="click" /></div> </form> </body> </html> 3.Response.End method: The Response.End method can be used to stop any further processing of the web page from the point where you can Response.End.The end method orders the web server to stop processing the script.The current results are returned and no further processing occurs.If Response.buffer is set to True,Response.End willflush the buffer and then End,
Compiled By Prof. Vaibhav Vasani

Example:To stop further processing :

<%Response.Write(welcome Resonse.End

dear)

Response.Write(how are u?)this message is never displayed 4.Response.Clear method: Response.Clear method can be used to remove the buffer HTML output.The Response.Buffer should be set to True otherwise you will get the runtime error. Syntax: Response.Clear() Example: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Q9.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <% Response.Buffer=True%> <p>hello</p> <% Response.Clear()%> </form> </body> </html>. (b) [Format]Write the steps for binding datagrid to control step by step.
Compiled By Prof. Vaibhav Vasani

Ans. To bind a data grid to a table, you can set the data grid's DataSource property (usually to a dataset, such as dsDataSet) and DataMember property (usually to text naming a table like "authors"). At run time, you can set both of these properties at once with the built-in data grid method SetDataBinding (data grids are the only controls that have this method): DataGrid1.SetDataBinding(dsDataSet, "sched") You can use these data sources with the data grid's DataSource property:

DataTable objects DataView objects DataSet objects DataViewManager objects single dimension arrays

Steps for binding datagrid control to data: Connect to the database Connecting to the database involves creating a connection, a data adapter, and a dataset. Creating a data adapter Create a data adapter as shown below: Dim adap = New OleDbDataAdapter("select * from sched", myconnection) Create a Dataset Create a dataset for storing the records To fill the dataset with records from the database, write the following statement in the Load event of the form. adap.Fill(ds,
Compiled By Prof. Vaibhav Vasani

"sched")

Bind the data to Windows Form control: DataGrid1.SetDataBinding(dsDataSet, "sched")

EXAMPLE: Imports System.Data.OleDb Imports System.Data Public Class Form1 Dim myconnection As OleDbConnection Dim adap As OleDbDataAdapter Dim ds As Data.DataSet Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myconnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sch.mdb;") myconnection.Open() adap = New OleDbDataAdapter("select * from sched", myconnection) ds = New Data.DataSet adap.Fill(ds, "sched") DataGrid1.SetDataBinding(ds, "sched") myconnection.Close() Console.Read() End Sub End Class

(c) Explain the concept of methods and collection in ASP.Net example. (d) Explain how transaction db is designed .

with

Compiled By Prof. Vaibhav Vasani

Você também pode gostar