WINDOWS COMMON CONTROLS DEFAULT EVENT HANDLERS.

Slides:



Advertisements
Similar presentations
Chapter 1: An Introduction to Visual Basic 2012
Advertisements

CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab2 Managing Controls.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
Microsoft Visual Basic 2012 CHAPTER TEN Incorporating Databases with ADO.NET.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
BIM313 – Advanced Programming Simple Controls 1. Contents Traditional Controls – Labels, Text Boxes, Buttons, Check Boxes, List Boxes, Combo Boxes Advanced.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
IE 411/511: Visual Programming for Industrial Applications
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
CIS 338: VB.NET Components Dr. Ralph D. Westfall April, 2011.
Graphical User Interfaces 2 Tonga Institute of Higher Education.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Designer Basics.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Creating a Multiple-Form Interface.
Introduction to Windows Forms Application By N Hanumantha Rao MCA By N Hanumantha Rao MCA.
Controls. Common properties Height – Height of the control Left – Left of the control Width – width of a control Top - From the screen top Font – Foreground.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
DataGridView. Displaying data in a tabular format is a task you are likely to perform frequently. The DataGridView control is designed to be a complete.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
.NET Data Access and Manipulation
1 Chapter 6: Creating Oracle Data Block Forms. 2 Forms  Application with a graphical user interface that looks like a paper form  Used to insert, update,
Graphical User Interface Concepts - Part 1 Session 08 Mata kuliah: M0874 – Programming II Tahun: 2010.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Chapter 1: An Introduction to Visual Basic .NET
ASP.NET Programming with C# and SQL Server First Edition
Data Access with ADO.NET
Introduction to ADO.NET
Introduction to Database Processing with ADO.NET
Microsoft Visual Basic 2005: Reloaded Second Edition
Introduction to Database Processing with ADO.NET
Object Orientated Programming using C#
BUILDING WINDOWS APPLICATION
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
Incorporating Databases with ADO.NET
3.01 Apply Controls Associated With Visual Studio Form
Reference: COS240 Syllabus
Enhancing Forms with OLE Fields, Hyperlinks, and Subforms
Introduction to the Visual C# 2005 Express Edition IDE
Visual programming Chapter 3: GUI (Graphical User Interface) Part I
Incorporating Databases with ADO.NET
Variables and Arithmetic Operations
Visual Basic.
Chapter 2 – Introduction to the Visual Studio .NET IDE
C++ programming in Windows environment Text controls in the program
Copyright © 2006 Thomas P. Skinner
Database Objects 1/12/2019 See scm-intranet.
Static and Dynamic Web Pages
Visual Studio.
Chapter 10 ADO.
Database Applications
6. WinForms 2003 C# GUI - Basics.
Chapter 10 Accessing Database Files
Visual C# - GUI and controls - 1
Programming In Visual Basic.NET
Chapter 2 User Interface Design
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Week 2: WINDOWS PROGRAMMING
Unit J: Creating a Database
Presentation transcript:

WINDOWS COMMON CONTROLS DEFAULT EVENT HANDLERS

HOW TO ADD THE DATA’S TO CONTROL SLNO CONTROLS HOW TO ADD THE DATA’S TO CONTROL DEFAULT EVENT HANDLER 1. Form Form1.Text = “Chettinad”; private void Form1_Load(object sender, EventArgs e){ }   2. Button Button1.Text=”Click Here”; private void button1_Click(object sender, EventArgs e) { } Label Label.Text=”Enter the A Value”; private void label1_Click(object sender, EventArgs e) { } 3. Textbox Textbox1.Text=”Insert the Text Here”; private void textBox1_TextChanged(object sender, EventArgs e) { } 4. Checkbox Checkbox1.Text=”Addition”; private void checkBox1_CheckedChanged(object sender, EventArgs e) { } 5. Radiobutton Radiobutton1.Text=”Addition”; private void radioButton1_CheckedChanged(object sender, EventArgs e) { } 6. CheckListBox CheckListbox.Items.add(“Add”); CheckLIstbox.Items.add(“Sub”); private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) { } 7. ComboBox Combobox.Items.add(“Add”); Combobox.Items.add(“Sub”); private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } 8. ListBox Listbox1.Items.add(“Add”); Listbox1.Items.add(“Sub”); private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } 9. Picturebox Picturebox1.Load(“Picture File Path”) private void pictureBox1_Click(object sender, EventArgs e) { } 10. Progressbar NIL private void progressBar1_Click(object sender, EventArgs e) { } 11. Treeview Treeview1.Items.add(“Add”); TreeView1.Items.add(“Sub”); private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { } 12. Listview Listview1.Items.add(“Add”); Listview1.Items.add(“Sub”); private void listView1_SelectedIndexChanged(object sender, EventArgs e) { } 13. Groupbox Groupbox1.Controls.add(button1); private void groupBox1_Enter(object sender, EventArgs e) { } 14. Timer Nil private void timer1_Tick(object sender, EventArgs e) { }

WINDOWS COMMON CONTROL PROPERTIES

SLNO PROPERITE NAME PROPERTY VALUE DESCRIPTION 1. Name “Form1” Indicates the name used in code to identify the object or control 2. Autosize True or False Specifies whether a control will automatically size iteselft to fit its contents 3. BackColor Color Name The background color of the component 4. BackgroundImage Image File path The background image used for the control 5. Enabled Indicates whether the control is enabled 6. ForeColor The foreground color of this component, which is used to display text. 7. Font Font Face, Font Style, Font size, Font Color The font used to display text in the control. 8. Location X, Y axis The coordinates of the upper – left corner of the control relative to the upper – left corner of its container 9. Locked The Locked property determines if we can move or resize the control 10. Size Width and Height The size of the control in pixels 11. Text “Text of the Particular Control” The text associated with the control 12. Visible Determines whether the control is visible or hidden 13. TabIndex Index value to the control Determines the index in the TAB order that this control will occupy. 14. TabStop Indicates whether the user can use the TAB key to give focus to the control. 15. TextAlign Left, Center, Rigth The alignment of the text that will be displayed on the control. 16. ToolTip Text Tool Tip Text on the particular Control Determines the tool tip shown when the mouse hovers over the control. 17. UseMnemonic If true, the first character proceeded by an ampersand (&) will be used as the button’s mnemonic key.

EXTRA PROPERTIES FOR THE WINDOWS CONTROLS

SLNO CONTROL NAME PROPERITE NAME PROPERTY VALUE DESCRIPTION 1.   PictureBox Image .jpg or .bmp or .gif The image display in the PictureBox. WaitOnLoad True or False Controls whether processing will stop until the image is loaded. 2. RadioButton Checked Indicates whether the component is in the checked state. 3. Checkbox CheckState Unchecked or Checked or Intermediate Indicates the state of the component. ThreeState Indicates whether the CheckBox will allow three check states rather than two. 4. TextBox HideSelection Indicates that the selection should be hidden when the edit control loses focus. MaxLength 32767 Specifies the maximum number of character that can be entered into the edit control. Multiline Controls whether the text of the edit control can span more than one line. PasswordChar ***** or &&&&& Indicates the character to display for password input for single – line edit controls. ScrollBars None, Horizontal, Vertical Indicates, for multiline edit contrls, which scroll bars, will be shown for this control. WordWrap Indicates if lines are automatically word – wrapped for multiline edit controls. ShortcutsEnabled Indicates whether shortcuts defined for the control are enabled. 5. Form ControlBox Determines whether a form has a Control / System menu box. Cursor Different Cursor Control The Cursor that appear when the pointer moves over the control. MaximizeBox Determines whether a form has a maximize box in the upper – right corner of its caption bar. MinimizeBox Determines whether a form has a minimize box in the upper – right corner of its caption bar. StartPosition Windows appears for the different location Determines the position of a form when it first appears. WindowState Normal, Maximize, Minimize 6. Timer Enabled Enables generation of Elapsed events Interval 1000 (milliseconds) The frequency of Elapsed events in milliseconds 7. ProgressBar Minimum The lower bound of the range this ProgressBar is working with. Maximum 1000 The upper bound of the range this ProgressBar is working with.

MessageBox Program using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form public Form1() InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Welcome to Chettinad College of Engineering and Technology"); } private void button2_Click(object sender, EventArgs e) MessageBox.Show("Welcome", "Chettinad", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop); private void button3_Click(object sender, EventArgs e) DialogResult ans = MessageBox.Show("Arithmetic Operation", "Welcome", MessageBoxButtons.OKCancel); if (ans == DialogResult.OK ) MessageBox.Show("Click OK Button"); else if(ans == DialogResult.Cancel) MessageBox.Show("Click Cancel Button"); private void button4_Click(object sender, EventArgs e) Button_Control f2 = new Button_Control(); f2.Show();

Addition of Two Numbers using Button, Label and Textbox using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Button_Control : Form public Button_Control() InitializeComponent(); } private void button1_Click(object sender, EventArgs e) int a, b, c; a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); c = a + b; textBox3.Text = c.ToString();

Arithmetic Operation using Checkboxes private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked == true) checkBox2.Checked = false; checkBox3.Checked = false; checkBox4.Checked = false; checkBox5.Checked = false; x = textBox1.Text; y = textBox2.Text; a = int.Parse(x); b = int.Parse(y); c = a + b; textBox3.Text = c.ToString(); } } namespace WindowsApplication1 { public partial class CheckBox_Control : Form public CheckBox_Control() InitializeComponent(); } int a, b, c; string x, y;

private void checkBox3_CheckedChanged(object sender, EventArgs e) { if (checkBox3.Checked == true) checkBox1.Checked = false; checkBox2.Checked = false; checkBox4.Checked = false; checkBox5.Checked = false; x = textBox1.Text; y = textBox2.Text; a = int.Parse(x); b = int.Parse(y); c = a * b; textBox3.Text = c.ToString(); } private void checkBox2_CheckedChanged(object sender, EventArgs e) { if (checkBox2.Checked == true) checkBox1.Checked = false; checkBox3.Checked = false; checkBox4.Checked = false; checkBox5.Checked = false; x = textBox1.Text; y = textBox2.Text; a = int.Parse(x); b = int.Parse(y); c = a - b; textBox3.Text = c.ToString(); }

private void checkBox4_CheckedChanged(object sender, EventArgs e) { if (checkBox4.Checked == true) checkBox1.Checked = false; checkBox2.Checked = false; checkBox3.Checked = false; checkBox5.Checked = false; x = textBox1.Text; y = textBox2.Text; a = int.Parse(x); b = int.Parse(y); c = a / b; textBox3.Text = c.ToString(); } private void checkBox5_CheckedChanged(object sender, EventArgs e) { if (checkBox5.Checked == true) checkBox1.Checked = false; checkBox2.Checked = false; checkBox3.Checked = false; checkBox4.Checked = false; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; }

Arithmetic Operation using Radio Buttons private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked == true) radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; try a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); } catch c = a + b; textBox3.Text = c.ToString(); using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Radio_Control : Form int a, b, c; public Radio_Control() InitializeComponent(); }

private void radioButton2_CheckedChanged(object sender, EventArgs e) { if (radioButton2.Checked == true) radioButton1.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); c = a - b; textBox3.Text = c.ToString(); } private void radioButton3_CheckedChanged(object sender, EventArgs e) { if (radioButton3.Checked == true) radioButton1.Checked = false; radioButton2.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); c = a * b; textBox3.Text = c.ToString(); }

private void radioButton4_CheckedChanged(object sender, EventArgs e) { if (radioButton4.Checked == true) radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton5.Checked = false; a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); c = a / b; textBox3.Text = c.ToString(); } private void radioButton5_CheckedChanged(object sender, EventArgs e) { if (radioButton5.Checked == true) radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } private void Form6_Load(object sender, EventArgs e) radioButton5.Checked = false;

Arithmetic Operation using ComboBox and ListBox private void Form5_Load(object sender, EventArgs e) { comboBox1.Items.Add("Addition"); comboBox1.Items.Add("Subtraction"); comboBox1.Items.Add("Multiplication"); comboBox1.Items.Add("Division"); comboBox1.Items.Add("Clear"); listBox1.Items.Add("Addition"); listBox1.Items.Add("Subtraction"); listBox1.Items.Add("Multiplication"); listBox1.Items.Add("Division"); listBox1.Items.Add("Clear"); } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form5 : Form int a, b, c; public Form5() InitializeComponent(); }

private void listBox1_SelectedIndexChanged(object sender, EventArgs e) private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); if (comboBox1.SelectedIndex == 0) c = a + b; textBox3.Text = c.ToString(); } if (comboBox1.SelectedIndex == 1) c = a - b; if (comboBox1.SelectedIndex == 2) c = a * b; if (comboBox1.SelectedIndex == 3) c = a / b; if (comboBox1.SelectedIndex == 4) textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); if (listBox1.SelectedIndex == 0) c = a + b; textBox3.Text = c.ToString(); } if (listBox1.SelectedIndex == 1) c = a - b; if (listBox1.SelectedIndex == 2) c = a * b; if (listBox1.SelectedIndex == 3) c = a / b; if (listBox1.SelectedIndex == 4) textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } }

Arithmetic Operation using CheckListBox private void Checkboxlist_Control_Load(object sender, EventArgs e) { checkedListBox1.Items.Add("Addition"); checkedListBox1.Items.Add("Subtraction"); checkedListBox1.Items.Add("Multiplication"); checkedListBox1.Items.Add("Division"); checkedListBox1.Items.Add("Clear"); } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Checkboxlist_Control : Form public Checkboxlist_Control() InitializeComponent(); } int a, b, c;

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) { a = int.Parse (textBox1 .Text ); b = int.Parse (textBox2 .Text ); if (checkedListBox1.SelectedIndex == 0) c = a + b; textBox3.Text = c.ToString(); } if (checkedListBox1.SelectedIndex == 1) c = a - b; if (checkedListBox1.SelectedIndex == 2) c = a * b; if (checkedListBox1.SelectedIndex == 3) c = a / b; if (checkedListBox1.SelectedIndex == 4) textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = "";

PROGRAM FOR THE PICTURE BOX namespace WindowsApplication1 { public partial class Picturebox_Control : Form public Picturebox_Control() InitializeComponent(); pictureBox1.Load(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\sunset.jpg"); } private void button1_Click(object sender, EventArgs e) pictureBox1 .Image = Image .FromFile (@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\sunset.jpg"); pictureBox1.ImageLocation = "http://www.functionx.com/cars/civic.gif"; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

PROGRAM FOR THE PROGRESS BAR private void Progress_Control_Load(object sender, EventArgs e) { progressBar1.Minimum = 0; progressBar1.Maximum = 1000; } private void button1_Click(object sender, EventArgs e) progressBar1.Increment(10); using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Progress_Control : Form public Progress_Control() InitializeComponent(); }

PROGRAM FOR THE PROGRESS BAR AND THE TIMER private void Timer_Control_Load(object sender, EventArgs e) { progressBar1.Minimum = 0; progressBar1.Maximum = 1000; } private void timer1_Tick(object sender, EventArgs e) progressBar1.Increment(100); using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Timer_Control : Form public Timer_Control() InitializeComponent(); } NOTE In the Timer Control Properties change the Enabled properties is True and the set the Time Interval ( not Zero)

PROGRAM FOR THE LIST VIEW private void button1_Click(object sender, EventArgs e) { listView1.View = View.LargeIcon; } private void button2_Click(object sender, EventArgs e) listView1.View = View.SmallIcon; private void button3_Click(object sender, EventArgs e) listView1.View = View.List; private void button4_Click(object sender, EventArgs e) listView1.View = View.Details; private void button5_Click(object sender, EventArgs e) listView1.Clear(); using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Listview_Control : Form public Listview_Control() InitializeComponent(); }

Creating Calculator Program using the Code File (Design view and Code view Creating to the User) //1. Include the Namespaces// using System; using System.Drawing; using System.Windows.Forms; //2. Create a class that inherit from Form class of Windows// public class ButtonDemo: Form { //3.Create the Controls // Button b0; Button b1; Button b2; Button b3; Button b4; Button b5; Button b6; Button b7; String s1=""; String s2=""; String op=""; TextBox t1; //4.Create the class Constructor methosd to invoke the components to be initialized// public ButtonDemo() //5. Invoke the method to initialize the components// InitializeComponent(); }

private void InitializeComponent() { // Initilaize the components properties and Events// t1=new TextBox(); t1.Name="textbox1"; t1.Location=new Point(50,80); t1.Size=new System.Drawing.Size(80,50); this.Controls.Add(t1); b0=new Button(); b0.Location=new Point(50,120); b0.Size=new System.Drawing.Size(25,25); b0.Text="0"; b0.Click+=new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b0); b1=new Button(); b1.Location=new Point(75,120); b1.Size=new System.Drawing.Size(25,25); b1.Text="1"; b1.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b1); b2 = new Button(); b2.Location = new Point(100, 120); b2.Size = new System.Drawing.Size(25, 25); b2.Text = "2"; b2.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b2);

b6.Location = new Point(100, 145); b3 = new Button(); b3.Location = new Point(125, 120); b3.Size = new System.Drawing.Size(25, 25); b3.Text = "3"; b3.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b3); b4 = new Button(); b4.Location = new Point(50, 145); b4.Size = new System.Drawing.Size(25, 25); b4.Text = "4"; b4.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b4); b5 = new Button(); b5.Location = new Point(75, 145); b5.Size = new System.Drawing.Size(25, 25); b5.Text = "+"; b5.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b5); b6 = new Button(); b6.Location = new Point(100, 145); b6.Size = new System.Drawing.Size(25, 25); b6.Text = "-"; b6.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b6); b7 = new Button(); b7.Location = new Point(125, 145); b7.Size = new System.Drawing.Size(25, 25); b7.Text = "="; b7.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b7); this.Name="Button Demo"; this.Text="Button Demo"; }

else if(sender.Equals(b7)) { if(op.Equals("+")) //Events handling Procedures// private void btnsubmit_Click(Object sender, EventArgs e) { if(sender.Equals(b0)) t1.Text += "0"; } else if (sender.Equals(b1)) t1.Text += "1"; else if (sender.Equals(b2)) t1.Text+="2"; else if (sender.Equals(b3)) t1.Text += "3"; else if (sender.Equals(b4)) t1.Text += "4"; else if (sender.Equals(b5)) s1=t1.Text; t1.Text=""; op=b5.Text; } else if(sender.Equals(b7)) { if(op.Equals("+")) MessageBox.Show((Int32.Parse(t1.Text)+Int32.Parse(s1)).ToString()); public class Demo static void Main() System.Windows.Forms.Application.Run(new ButtonDemo());

Output of the Above program is

Data Access with ADO.NET

ADO.NET relational data bases XML data other data sources Is the .NET technology for accessing structured data Uniform object oriented interface for different data sources relational data bases XML data other data sources Designed for distributed and Web applications Provides 2 models for data access connection-oriented connectionless

Idea of Universal Data Access Connection of (object-oriented) programming languages and relational data bases Uniform programming model and API Special implementations for data sources (providers)

Data Providers Microsoft’s layered architecture for data access

History of Universal Data Access (Microsoft) ODBC OLE DB ADO (ActiveX Data Objects) ADO.NET ADO ADO.NET connection-oriented connection-oriented + connectionless sequential access sequential access + main-memory representation with direct access only one table supported more than one table supported COM-marshalling XML-marshalling

DIFFERENCES BETWEEN ADO AND ADO .NET ADO has one main object that is used to reference data, called the Record set object. This object basically gives you a single table view of your data, although you can join tables to create a new set of records.   With ADO.NET, you have various objects that allow you to access data in various ways. The Dataset object will actually allow you to store the relational model of your database. This allows you to pull up customers and their orders, accessing/updating the data in each related table individually. ADO works with connected data. This means that when you access data, such as viewing and updating data, it is real-time, with a connection being used all the time. This is barring, of course, you programming special routines to pull all your data into temporary tables.   ADO.NET uses data in a disconnected fashion. When you access data, ADO.NET makes a copy of the data using XML. ADO.NET only holds the connection open long enough to either pull down the data or to make any requested updates. This makes ADO.NET efficient to use for Web applications. It's also decent for desktop applications. In ado user can move sequentially to database In ado.net user can move one data from one table to another table.   ADO allows you to create client-side cursors only ADO.NET we don't have any cursor support in ADO.NET. ADO allows you to persist records in XML format ADO.NET allows you to manipulate your data using XML as the primary means. This is nice when you are working with other business applications and also helps when you are working with firewalls because data is passed as HTML and XML.   COM – marshalling XML – marshalling

Architecture of ADO.NET

Architecture represents connection to data source DbConnection represents connection to data source DbCommand represents a SQL command DbTransaction represents a transaction commands can be executed within a transaction DataReader result of a data base query allows sequential reading of rows

DataTables and DataColumns DataAdapter DataAdapter as a bridge between the DataSet and the data source, which is underlying database DataAdapter provides the Fill() method to retrieve data from the database and populate the dataset DataSet A DataSet represents a complete set of data including the tables that contain, order, and constrain the data, as well as the relationships between the tables. DataTables and DataColumns The DataTable has a number of public properties, including the columns collection, which returns the DataColumnCollection object ,which in trun consists of DataColumn objects. Each DataColumn object represents a column in a table DataRelations DataRelation represents a relationship between two tables through DataColumn objects. For example, in the Northwind database the Customers table is in a relationship with the Orders table through the CustomerID column DataRows - DataTable’s Rows collection returns a set of rows for that table. Use this collection to examine the results of queries against the database, iterating throught the rows to examine each record in trun.

Connection-oriented versus Connectionless Keeps the connection to the data base alive Always up-to-date data Intended for applications with: short running transactions only a few parallel access operations Connectionless No permanent connection to the data source Data cached in main memory Changes in main memory may be in conflict with changes in data source many parallel and long lasting access operations (e.g.: Web applications)

IDbConnection: Property ConnectionString

ExecuteNonQuery Method

ExecuteScalar Method

ADO.NET and Transactions 2 transaction models local transactions: transactions for one connection provided by ADO.NET distributed transactions: transactions for several connections usage of Microsoft Distributed Transaction Component (MSDTC) namespace System.Transaction