C# programming with database Basic guideline. First step Install SQL Server 2008/2010 (Professional edition if possible) Install Visual Studio 2008/2010.

Slides:



Advertisements
Similar presentations
By Chris Pascucci and FLF
Advertisements

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.
Introduction to Database Processing with ADO.NET.
1 ADO.NET. 2.NET Framework Data Namespaces System.Data –Base set of classes and interfaces for ADO.NET System.Data.Common –Classes shared by the.NET Data.
ADO. NET. What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
C# Programming: From Problem Analysis to Program Design1 Working with Databases C# Programming: From Problem Analysis to Program Design 3 rd Edition 14.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
Objective In this session we will discuss about : What is ADO. NET ?
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
CIS 764 – Presentation Somil Chandwani.  With Microsoft Data Access Components (MDAC), developers can connect to and use data from a wide variety of.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
A Simple Introduction. What is ADO.net? First the word ADO stands for ActiveX Data Objects And it is an integral part of.Net Framework of Microsoft hence.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
.NET Data Access and Manipulation ADO.NET. Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
10/26/20151 Chapter 3 Introduction to ADO.NET In this chapter, you will: Learn the basic classes in ADO.NET and its architecture Learn the different ADO.NET.
ASP.NET Rina Zviel-Girshin Lecture 5
Module 9: Accessing Relational Data Using Microsoft Visual Studio.NET.
Module 7: Accessing Data by Using ADO.NET
What is database?  Any Method for access info into Application from DataBase?  ODBC is standard for Accessing Data.  Problem with ODBC:  Information.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
An Introduction to ADO.Net Marmagna Desai.NET Seminar, Fall-2003.
ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.
ADO.NET connections1 Connecting to SQL Server and Oracle.
1 11/10/05CS360 Windows Programming ADO.NET. 2 11/10/05CS360 Windows Programming ADO.NET  Behind every great application is a database manager o Amazon.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
COP2360 – C# Programming Chapter 14 – Nov 25, 2015.
HNDIT Rapid Application Development
Databases – Unit 3 & 4.  SQL is not restricted to a specific database, however in class we will be looking at the two major database programmes in use.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
Module 4 Introduction ADO.NET.
C# .NET Software Development
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
Active Data Objects Using.Net ADO.Net Farooq Ahmed Amna Umber Summayya Shehzad.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
Querying Information in a Database. CONTENTS Relational Database Systems Creating Database with SQL Server Reading Data with LINQ Requirements to Get.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 The SqlCommand Object ADO.NET - Lesson 03  Training time: 15 minutes  Author:
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
C# 1 CSC 298 ADO.NET. C# 2 ADO.NET  A data access technology that maps very well to the world of the web (disconnected architecture)  data is retrieved.
 ADO.NET is an object-oriented set of libraries that allows you to interact with data sources  Commonly, the data source is a database, but it could.
Integrating Data Lesson 6.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
ASP.NET Programming with C# and SQL Server First Edition
Introduction to ADO.NET
Accessing Databases using Ado.net
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
Lecture 6 VB.Net SQL Server.
ADO.NET Accessing Databases in VS.NET
Tonga Institute of Higher Education
An Introduction to Entity Framework
Chapter 10 ADO.
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to Database Programming through ADO. NET
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

C# programming with database Basic guideline

First step Install SQL Server 2008/2010 (Professional edition if possible) Install Visual Studio 2008/2010  you can begin to do!!!

sql-server-2008-step-by-step-guide.aspx

SQL Server After installation,

ADO.NET 7 Includes number of classes that can be used to retrieve, manipulate, and update data in databases Can work with databases in a disconnect manner Database table(s) can be retrieved to a temporary file To retrieve data first, you must connect to the database ADO.NET uses a feature called data providers to connect, execute commands, and retrieve results from a database

Data Providers 8 Microsoft SQL Server Applications using SQL Server 7.0 or later Oracle Applications using Oracle data sources Object Linking and Embedding Database (OLE DB) Applications that use Microsoft Access databases Open Database Connectivity (ODBC) Applications supported by earlier versions of Visual Studio

Data Providers ( continued ) 9 Classes are encapsulated into a different namespace by provider Four core classes make up each data provider namespace Connection Command DataReader or DataSet DataAdapter

10 Data Providers ( continued )

C# programming language Go to Settings.settings

C# programming language Create a new class to work with Database, for example DatabaseHelper class In this class, create the connection such as: // declare the class level connection variable SqlConnection conn; // init with the above connection string in the constructure of the class conn = new SqlConnection(global::DoAnTinHocProject.Properties.Settings.Default.DoAnConnectionString); conn.Open();

C# programming language public DataSet SelectData(string SQLCommand) { // hàm m ẫ u đ ể th ự c thi các câu l ệ nh select, tr ả v ề d ữ li ệ u đư ợ c ch ứ a trong dataset DataSet ds = new DataSet(); try { if (sqlconn.State != ConnectionState.Open) sqlconn.Open(); SqlCommand sqlComm = new SqlCommand(); SqlDataAdapter sqlAdp = new SqlDataAdapter(); sqlComm.Connection = sqlconn; sqlComm.CommandText = SQLCommand; sqlComm.CommandType = CommandType.Text; sqlAdp.SelectCommand = sqlComm; sqlComm.ExecuteNonQuery(); sqlAdp.Fill(ds); return ds; } catch (Exception) { return null; } }

C# programming language Public int ExecuteCommand(string SQLCommand) { // hàm m ẫ u th ự c thi các câu l ệ nh insert, update, delete) try { if (sqlconn.State != ConnectionState.Open) sqlconn.Open(); SqlCommand sqlComm = new SqlCommand(); sqlComm.Connection = sqlconn; sqlComm.CommandText = SQLCommand; sqlComm.CommandType = CommandType.Text; return sqlComm.ExecuteNonQuery(); } catch (Exception) { return -1; }

C# programming language The example of using the above functions - To display data, use the DataGridView Control

C# programming language //Load data on datagridview control, transfer the SELECT command into the function SelectData DatabaseHelper h = new DatabaseHelper(); dataGridView1.DataSource = h.SelectData("Select * from Workdays ").Tables[0];

C# programming language // To insert data, transfer the Insert statement to the function ExecuteCommand DatabaseHelper h = new DatabaseHelper(); h.ExecuteCommand(“Insert into Workdays (ID, Day) values (1, ‘Monday’)”); // Update, Delete is similar with this