Lab 4 (Introduction to C# and windows Form Applications)

Similar documents
if (say==0) { k.commandtext = "Insert into kullanici(k_adi,sifre) values('" + textbox3.text + "','" + textbox4.text + "')"; k.

Programming with ADO.NET

ADO.NET 2.0. database programming with

How to use data sources with databases (part 1)

For this example, we will set up a small program to display a picture menu for a fast food take-away shop.

Mainly three tables namely Teacher, Student and Class for small database of a school. are used. The snapshots of all three tables are shown below.

C# is intended to be a simple, modern, general-purpose, objectoriented programming language. Its development team is led by Anders Hejlsberg.

3 Customer records. Chapter 3: Customer records 57

UNIT-3. Prepared by R.VINODINI 1

Quick Guide for the ServoWorks.NET API 2010/7/13

Philadelphia University Faculty of Information Technology. Visual Programming. Using C# -Work Sheets-

Database Communication in Visual Studio/C# using Web Services

> ADO.NET: ActiveX Data Objects for.net, set of components used to interact with any DB/ XML docs

Chapter 3. Windows Database Applications The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

Skinning Manual v1.0. Skinning Example

Activating AspxCodeGen 4.0

Introduction. Three button technique. "Dynamic Data Grouping" using MS Reporting Services Asif Sayed

In the previous chapter we created a web site with images programmed into HTML page code using commands such as: <img src="images/train.

C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies. Objectives (1 of 2)

Introduction to using Visual Studio 2010 to build data-aware applications

Advanced Programming C# Lecture 5. dr inż. Małgorzata Janik

Hands-On Lab. Introduction to SQL Azure. Lab version: Last updated: 12/15/2010

Windows Database Applications

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

C# winforms gridview

Introduce C# as Object Oriented programming language. Explain, tokens,

CALCULATOR APPLICATION

Creating a new CDC policy using the Database Administration Console

DOWNLOAD OR READ : PROGRAMMING FUNDAMENTALS USING MICROSOFT VISUAL BASIC NET PDF EBOOK EPUB MOBI

Working with Data in ASP.NET 2.0 :: Displaying Binary Data in the Data Web Controls Introduction

ADO.NET Overview. Connected Architecture. SqlConnection, SqlCommand, DataReader class. Disconnected Architecture

WinForms Charts How to Determine the Chart Element underneath. the Mouse Cursor and Display Series Point s Data in a Tooltip

Writing Reports with Report Builder and SSRS Level 2

Hands-On Lab. Introduction to SQL Azure. Lab version: Last updated: 11/16/2010

8 Library loan system

Insert Data into Table using C# Code

CIS Intro to Programming in C#

20483BC: Programming in C#

2310C VB - Developing Web Applications Using Microsoft Visual Studio 2008 Course Number: 2310C Course Length: 5 Days

Building Datacentric Applications

VS2010 C# Programming - DB intro 1

Working with Data in ASP.NET 2.0 :: Using Parameterized Queries with the SqlDataSource Introduction

CSC 330 Object-Oriented

Final Documentation. Created By: Ahnaf Salam Adam Castillo Sergio Montejano Elliot Galanter

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

About the Authors Introduction p. 1 Exploring Application Architectures p. 9 Introduction p. 9 Choosing the "Right" Architecture p.

10265: Developing Data Access Solutions with Microsoft Visual Studio 2010 Duration: 5 Days Method: Instructor-Led

Advances in Programming Languages

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

CST242 Windows Forms with C# Page 1

Datalogging and Monitoring

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

3-tier Architecture Step by step Exercises Hans-Petter Halvorsen

Mastering VB.NET using Visual Studio 2010 Course Length: 5 days Price: $2,500

Answer on Question# Programming, C#

How to create a simple ASP.NET page to create/search data on baan using baan logic from the BOBS client sample.

All India Council For Technical Skill Development (AICTSD) In Association with IITians Embedded Technosolution

1. A Web Form created in Visual Basic can only be displayed in Internet Explorer. True False

C# MOCK TEST C# MOCK TEST I

Understanding Events in C#

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

Tackle Complex Data Binding in WinForms 2.0

Ingegneria del Software T. Interfaccia utente

Copy Datatable Schema To Another Datatable Vb.net

Introduction to Programming Using Java (98-388)

Unit 6 - Software Design and Development LESSON 4 DATA TYPES

Accessing Databases 7/6/2017 EC512 1

Windows 8. Rainer Stropek. System Architecture. System Architecture re of Windows Store Apps. Saves the day. software architects gmbh

ASP.net. Microsoft. Getting Started with. protected void Page_Load(object sender, EventArgs e) { productsdatatable = new DataTable();

COSE312: Compilers. Lecture 1 Overview of Compilers

Working with Data in ASP.NET 2.0 :: Uploading Files Introduction

2.1 Read and Write XML Data. 2.2 Distinguish Between DataSet and DataReader Objects. 2.3 Call a Service from a Web Page

Implementing and Maintaining Microsoft SQL Server 2008 Integration Services

Getting started 7. Setting properties 23

How to work with data sources and datasets

Course Syllabus C # Course Title. Who should attend? Course Description

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

Tutorial - Hello World

Problem description: After finishing the lab, the student will practice:

FDSc in ICT. Building a Program in C#

CST272 Getting Started Page 1

Instructions for writing Web Services using Microsoft.NET:

10267 Introduction to Web Development with Microsoft Visual Studio 2010

The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear.

Motivation was to facilitate development of systems software, especially OS development.

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Chapter 2. Ans. C (p. 55) 2. Which is not a control you can find in the Toolbox? A. Label B. PictureBox C. Properties Window D.

BUILDING APPLICATIONS USING C# AND.NET FRAMEWORK (OBJECT-ORIENTED PROGRAMMING, X428.6)

10267A CS: Developing Web Applications Using Microsoft Visual Studio 2010

Pentatonic Labs Final Documentation

Microsoft Official Courseware Course Introduction to Web Development with Microsoft Visual Studio

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

Working with Data in ASP.NET 2.0 :: Creating Stored Procedures and User Defined Functions with Managed Code Introduction

Introduction to Design Patterns

Real Application Security Administration

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

Call: SAS BI Course Content:35-40hours

Working with Data in ASP.NET 2.0 :: Using Existing Stored Procedures for the Typed DataSet s TableAdapters Introduction

Chapter 10. Database Applications The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

More Language Features and Windows Forms

Transcription:

Lab 4 (Introduction to C# and windows Form Applications) In this the following goals will be achieved: 1. C# programming language is introduced 2. Creating C# console application using visual studio 2008 3. Creating windows forms application using visual studio 2008 4. Connecting you windows forms application to the SQL Server. Introduction C# (programming language) (pronounced as see sharp) is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, procedural, generic, object-oriented (classbased), and component-oriented programming disciplines. It was developed by Microsoft within its.net initiative and later approved as a standard by Ecma (ECMA- 334) and ISO (ISO/IEC 23270:2006). C is one of the programming languages designed for the Common Language Infrastructure. C is built on the syntax and semantics of C++, allowing C programmers to take advantage of.net and the common language runtime. C is intended to be a simple, modern, general-purpose, object-oriented programming language.[6] Its development team is led by Anders Hejlsberg. The most recent version is C 5.0, which was released on August 15, 2012. Creating C# console application using visual studio 2008 To do this follow the following steps: 1. Open Microsoft visual studio 2008 application 2. File > New Project > Visual C# > Windows > Console application > and write down the project name.

3. You will find the following screen 4. The project tree is on the right side of your screen, your application starting point is Program.cs which you could consider holding the main function as in your c++ project. 5. Try writing the following code snippet Console.Out.WriteLine("Hello World this is test 1"); And run them by pressing ctrl+f5. 6. Try more code loop for example int i = 0; for (i = 0; i < 11; i++ ) { if (i == 5) { Console.Out.WriteLine("Reached the middle value"); } else { Console.Out.WriteLine("I value is: " + i); } } 7. Next we will create a class called Calculate and instantiate a new object from it and run it by doing the following: a. Right click on the project name > add > class, now write down the class name. b. The class is now created write the following snippet code in the class body public static double add(double num1, double num2) { return num1 + num2; } 8. Now return to program.cs and write the following code in order to test the class we have just created Console.Out.WriteLine("calc add test: " + Calculate.add(10.5, 36.7)); 9. String is very powerful object and we will use it later a lot you can create strings and convert them to integers by as the following snippet string number = "100"; int num_value = Int32.Parse(number); num_value++; Console.Out.WriteLine("Number value is: " + num_value);.

Creating windows forms application using visual studio 2008 To do this follow the following steps: 1. Open Microsoft visual studio 2008 application 2. File > New Project > Visual C# > Windows > Windows Forms Application> and write down the project name. 3. The project tree is on the right side of your screen, your application starting point is Program.cs which you could consider holding the main function as in your c++ project. 4. You will find a file created called Form1 and it represent the Form UI appearing in your left side of screen. 5. The first form which will appear to you on running is Form1 6. To add more forms right click on your project > Add > Windows Form and write down the form name. 7. To change the first form to appear go to program.cs and change Form1 in this line Application.Run(new Form1()); to your desired form name. 8. First task to implement is to create a form containing welcome text do this by following these steps: a. Click on toolbox drag Label and release on your form b.

c. Click on the label and change its text from the properties window appearing d. Try running now by pressing ctrl+f5. 9. Next task is to add a button and control its clicking action to display a message box by doing the following: a. Click on toolbox drag Button and release on your form b. Click on the button and change its text from the properties window appearing c. Now double click the button and the following window will appear

d. Write the following code snippet in order to show the message box String message = "This is My firsr app"; MessageBox.Show(message); e. Run now and test it 10. We now want to navigate from a form to another form do this by the following steps: a. Create a button like the previous task b. Write the following code snippet in order to show the next form // creating object of the new form Form1 f1 = new Form1(); // hiding the current form this.hide(); //showing the created form f1.show();. c. Run now and test it.. 11. Next task will be passing a parameter from a form and displaying it on the other do this by the following steps: a. Go to the first form and drag a TextBox component on it as well as a new button b. Go to the second form and create a Label on it c. Go to the second form cs file and add the following function to its code public void set_text(string text){ this.label1.text = text; }. d. Go to the first form double click the button used for navigation and write the following snippet code // // creating object of the second form Form1 f1 = new Form1(); this.hide(); // getting textfield text string message = this.textfield1.text;

// setting the text in next form label f1.set_text(text); f1.show();. 12. Final task will be creating a button on your final form of navigation to safely close the application by the following steps: a. Creating a button on your final form as in step 11 and write down the following snippet as its action Application.Exit();. Now you have finished learning an introductory lesson about C# by creating two types of projects console, and Windows Forms apps. Accessing data in visual studio: How to: Most applications revolve around reading and updating information in databases. To enable data integration in distributed, scalable applications, Visual Studio provides support for integrating data into your applications. Insert New Records into a Database To insert new records into a database, you can use command objects to interact and insert new records in your database (for example, SqlCommand). Example: Through this example we will do a windows form for course registeration as shown below and save the course details into table Course which is in database MiniUniversity

Double click on the Insert button to start writing in it s event handler then write your code a- you should add the following 2 liberiries using System.Data; and using System.Data.SqlClient; b- Create a new command object, set its Connection, CommandType, and CommandText properties. Note : you should write your server name in Data source and database name in Initial Catalog

Update Records in a Database: The following example updates existing records directly in a database using command objects, We uses the database MiniUniversity and Course table as an example. In the above example we updated the name of an existing course using it s code. Delete Records in a Database: The follwing example deletes an existing course from table course in database MiniUniversity.

private void Delete_Click(object sender, EventArgs e) { new SqlConnection(@"Data Source=HP-PC;Initial Catalog=MiniUniversity;Integrated Security=True"); con.open(); con); SqlCommand mycommand = new SqlCommand("delete from Course where CrsCode= '" + textbox1.text + "'", mycommand.executenonquery(); con.close(); } How to display data from a table: In the following example we will implement a master detail form for displaying the categories and its products.

1. from the data menu, click on add data source and continue the wizard by selecting the wanted database and needed tables ( in this example select table categories and table products) 2. from the data sources window you can choose either to select simple or complex data binding( details for simple data binding and DatagridView for complex) 3. for the table categories select details and drag it on your form 4. then add group box to your form and drag the products below the categories to the group box 5. this by default will add the components mentioned above such as dataset and binding navigator 6. run and test the application 7. to add new parameterized query, right click on the categoriestableadapter Add Query 8. start new query and open the query builder then add filter on categoryid column named @categoryid

9. This will add tool strip contain textbox and button, change their display text as shown 10. Run and test the application