Вы находитесь на странице: 1из 14

Assignment 3

Modern Tools and Technologies 2


CSE-456

Submitted To: Submitted By:

Mr. Sawal Tondon Navneet

Reg.No.7050070056
1. List out the core namespaces of the object used to bridge applications and databases.

Ans.

ADO.NET is a set of computer software components that programmers can use to access
data and data services.
Several important namespaces make up the ADO.NET data access technology. First, the
.NET Data Providers is implemented in the System. Data.SqlClient,
System.Data.OracleClient, System.Data.OleDbClient, and System.Data.Odbc namespaces.
The classes in these four namespaces provide the underlying database connectivity that’s
required by all of the other ADO.NET objects.
1. The System.Data.SqlClient namespace provides connectivity to SQL Server 7, SQL
Server 2000, and SQL Server 2005 databases.
2. The System.Data. OracleClient namespace provides connectivity to Oracle 8 and 9
databases.
3. The System.Data.OleDbClient namespace provides connectivity to SQL Server 6.5
and earlier databases, as well as Access and Oracle databases.
4. And the System.Data. Odbc namespace provides connectivity to legacy databases
using ODBC drivers.

2. Programmatically explain the construction of Dataset? Explain the functionalities of


binding source.
Ans.
Construction of dataset:
using System;
using System.Data;

namespace CrtDataSet
{
class Program
{
static void Main(string[] args)
{
//-- Instantiate the data set and table
DataSet SongDS = new DataSet();
DataTable songTable = SongDS.Tables.Add();

//-- Add columns to the data table


songTable.Columns.Add("ID", typeof(int));
songTable.Columns.Add("Band", typeof(string));
songTable.Columns.Add("Song", typeof(string));

//-- Add rows to the data table


songTable.Rows.Add(1, "Breaking Benjamin", "Diary of Jane");
songTable.Rows.Add(2, "Three Days Grace", "Pain");
songTable.Rows.Add(3, "Seether", "Fake It");
songTable.Rows.Add(4, "Finger Eleven", "Paralyzer");
songTable.Rows.Add(5, "Three Doors Down", "Citizen Soldier");

//-- Cycle thru the data table printing the values to the screen
foreach (DataTable table in SongDS.Tables)
{
foreach (DataRow row in table.Rows)
{
Console.WriteLine(row["Band"] + " ~ " + row["Song"]);
}
}
}
}
}

3. Write a C# code by Using ActiveXConnection and ActiveXCommand objects to connect


to and interact with a data source. Discuss the controlling of that code in detail?

Ans

Writing ActiveX Class in C#

01.using System;
02.using System.Runtime.InteropServices;
03.namespace ANamespace
04.{
05. 
06.  public interface ASignatures
07.  {
08.    string FName();
09.    string SName();
10.    int Age { get;} 
11.  }
12. 
13.  [ClassInterface(ClassInterfaceType.AutoDual)]
14.  public class AClass :ASignatures
15.  {
16.    public string FName()
17.    {
18.      return "Imran";
19.    }
20.    public string SName()
21.    {
22.      return "Nathani";
23.    }
24.    public int Age
25.    {
26.      get { return 24; }
27.    }
28.  }
29.}

Using the ActiveX control

We can then access our newly created ActiveX control via JavaScript. We will simply display
the data returned by the methods and property in alert boxes. The below code demonstrates how
we can access the properties in the ActiveX control.

01.<html>
02.<head>
03.  <script language="javascript">
04.    <!-- Load the ActiveX object  -->
05.    var x = new ActiveXObject("ANamespace.AClass");
06. 
07.    <!-- Access the Method -->
08.    alert(x.FName());
09.    alert(x.SName());
11.    <!-- Access the Property -->
12.    alert(x.Age);
13.  </script>
14.</head>
15.<body>
16.</body>
17.</html>
Part-B

4. Explain the hierarchy of windows forms components with necessary figure. Write the
programmatic steps to create the sample windows form application.
Ans. The following illustration shows the hierarchy of components and controls in the
System.Windows.Forms namespace:
first open Visual Studio and choose New Project. In the New Project window, create a new C#
Windows application, and name it ProgCSharpWindowsForm, as shown in Figure 13-2.

Figure 13-2. Creating a Windows Form application


Visual Studio responds by creating a Windows Form application and, best of all, putting you into
a design environment, as shown in Figure 13-3.

Figure 13-3. The design environment


The Design window displays a blank Windows Form (Form1). A Toolbox window is also
available, with a selection of Windows widgets and controls. If the Toolbox is not displayed, try
clicking the word "Toolbox," or selecting View Toolbox on the Visual Studio menu. You can
also use the keyboard shortcut Ctrl-Alt-X to display the Toolbox. With the Toolbox displayed,
you can drag a label and a button directly onto the form, as shown in Figure 13-3.

Figure 13-4. The Windows Form development environment


Before proceeding, take a look around. The Toolbox is filled with controls that you can add to
your Windows Form application. In the upper-right corner, you should see the Solution Explorer,
a window that displays all the files in your projects. In the lower-right corner is the Properties
window, which displays all the properties of the currently selected item. In Figure 13-4, the label
(label1) is selected, and the Properties window displays its properties.

You can use the Properties window to set the static properties of the various controls. For
example, to add text to label1, you can type the words "Hello World" into the box to the right
of its Text property. If you want to change the font for the lettering in the HelloWorld label,
click the Font property shown in the lower-right corner of Figure 13-5. (You can provide text in
the same way for your buttonbutton1by selecting it in the Property window and typing the word
"Cancel" into its Text property.)

Figure 13-5. Modifying the font


Any one of these steps is much easier than modifying these properties in code (though that is
certainly still possible).

Once you have the form laid out the way you want, all that remains is to create an event handler
for the Cancel button. Double-clicking the Cancel button will create the event handler, register it,
and put you on the code-behind page (the page that holds the source code for this form), in which
you can enter the event-handling logic, as shown in Figure 13-6.

Figure 13-6. After double-clicking the Cancel button


The cursor is already in place; you have only to enter the one line of code:

Application.Exit( );

Visual Studio .NET generates all the code necessary to create and initialize the components. The
complete source code is shown in Example 13-2, including the one line of code you provided
(shown in bold in this example) to handle the Cancel button-click event.

Example 13-2. Source code generated by the IDE

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ProgCSharpWindowsForm
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblOutput;
private System.Windows.Forms.Button btnCancel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1( )
{
//
// Required for Windows Form Designer support
//
InitializeComponent( );

//
// TODO: Add any constructor code
// after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose( );
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent( )
{
this.lblOutput = new System.Windows.Forms.Label( );
this.btnCancel = new System.Windows.Forms.Button( );
this.SuspendLayout( );
//
// lblOutput
//
this.lblOutput.Font = new System.Drawing.Font("Arial", 15.75F,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblOutput.Location = new System.Drawing.Point(24, 16);
this.lblOutput.Name = "lblOutput";
this.lblOutput.Size = new System.Drawing.Size(136, 48);
this.lblOutput.TabIndex = 0;
this.lblOutput.Text = "Hello World";
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(192, 208);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 1;
this.btnCancel.Text = "Cancel";
this.btnCancel.Click += new System.EventHandler(
this.btnCancel_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnCancel, this.lblOutput});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main( )
{
Application.Run(new Form1( ));
}

private void btnCancel_Click(object sender, System.EventArgs e)


{
Application.Exit( );
}

5. Create a Windows Form application that shows the coordinates of mouse pointer on the
tail of mouse pointer. Coordinate change must be effected. Eg:

Ans x,y
For this purpose, Control.MousePosition Property is used.

It gets the position of the mouse cursor in screen coordinates.

public static Point MousePosition { get; }

The MousePosition property returns a Point that represents the mouse cursor position at the time
the property was referenced. The coordinates indicate the position on the screen, not relative to
the control, and are returned regardless of whether the cursor is positioned over the control. The
coordinates of the upper-left corner of the screen are 0,0.

The MousePosition property is identical to the Cursor.Position property.

6. Write a code to develop a notepad with a button on toolbar that speak out the text.
Ans.

Add Speech Object Library reference to your Application using right click on Project & click on
Add Reference.

2). After Adding Referece of Speech Object Library Drag one textbox control on your WinForm
& give the name txttexttospeech.

3). After that put this belowed code on your page load event of the form.

1: SpVoice voice = new SpVoice();


2: voice.Voice = voice.GetVoices("Name=LH Michael", "Language=409").Item(0);
3: voice.Speak(txttexttospeech.Text, SpeechVoiceSpeakFlags.SVSFDefault);

Вам также может понравиться