Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
Advertisements

Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
ADO vs ADO.NET ADOADO.NET Client/server coupledDisconnected collection of data from data server Uses RECORDSET object (contains one table) Uses DATASET.
1 Introducing SQL Server  A Relational DBMS  A Powerful Client/Server DBMS Utilities range from:  Simple Database Creation/Maintenance To  Datawarehousing,
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.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Using ADO.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
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.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
VB.NET Database Access ISYS 812. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
.NET Mobile Application Development Data in Distributed Systems Accessing Data with.NET.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
Computer Science 317 Database Management Introduction to Web Access to Databases.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
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.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
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.
CHAPTER EIGHT Accessing Data Processing Databases.
.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.
CHAPTER EIGHT Accessing Data Processing Databases.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
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.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
ASP.NET Rina Zviel-Girshin Lecture 5
Module 9: Accessing Relational Data Using Microsoft Visual Studio.NET.
Session 8: ADO.NET. Overview Overview of ADO.NET What is ADO.NET? Using Namespaces The ADO.NET Object Model What is a DataSet? Accessing Data with ADO.NET.
Module 7: Accessing Data by Using ADO.NET
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
C# Programming in Depth Prof. Dr. Bertrand Meyer March 2007 – May 2007 Chair of Software Engineering Lecture 10: Database Lisa (Ling) Liu.
Mauricio Featherman, Ph.D. Washington St. University
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Building Data-Centric Smart Client Applications Rajiv Sodhi Microsoft India.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
HNDIT Rapid Application Development
2314 – Programming Language Concepts Introduction to ADO.NET.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
Module 4 Introduction ADO.NET.
ADO.NET in VB.NET 2005 ITE 370 4/26/2017.
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.
Module 5 Data Classes DataView – DataGridView Control 1.
Module 2: Using ADO.NET to Access Data. Overview ADO.NET Architecture Creating an Application That Uses ADO.NET to Access Data Changing Database Records.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
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
Integrating Data Lesson 6.
Introduction to 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.
Active Data Objects Binding ASP.NET Controls to Data
VB.NET Using Database.
Chapter 10 ADO.
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
Chapter 10 Accessing Database Files
Visual Studio + SQL Server Is Better
Active Data Objects Binding ASP.NET Controls to Data
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Module 3: Working with Local Data

Overview Using DataSets Using XML Using SQL Server CE

Lesson: Using DataSets ADO.NET Model Creating a DataSet Filling the DataSet Persisting the DataSet as an XML File Binding to a DataSet Using a DataGrid

Database DataSet Tables DataTable DataRowCollection DataColumnCollection ConstraintCollection DataRelationCollection ADO.NET Model XML.NET Data Provider Connection Transaction Command Parameters DataReader DataAdapter SelectCommand InsertCommand UpdateCommand DeleteCommand

Dim myDS As New DataSet("Project") Dim myDT As DataTable = _ myDS.Tables.Add("Task") myDT.Columns.Add("Name", _ System.Type.GetType("System.String")) myDT.Columns.Add("Start", _ System.Type.GetType("System.String")) myDT.Columns.Add("Duration", _ System.Type.GetType("System.String")) Creating a DataSet DataTable DataSet

Filling the DataSet Dim myDR As DataRow = _ myDS.Tables("Task").NewRow() myDR("Name") = "Design Code" myDR("Start") = "2/1/2003" myDR("Duration") = "2 days" myDS.Tables("Task").Rows.Add(myDR) NameStartDuration Design UI 1/1/2003I day Design Code2/1/20032 days

Practice: Using DataSets to Access Data Creating and filling a DataSet 1 1 Adding to a DataSet from a form 2 2

Persisting the DataSet as an XML File DataSet provides volatile storage Use the WriteXml method to save data Use the ReadXml method to populate data from the file myDataSet.WriteXml("win\tmp.xml") Dim myDataSet As New DataSet() myDataSet.ReadXml("win\tmp.xml")

Practice: Persisting the DataSet as XML Save a DataSet as an XML file 1 1 Verify the XML file 2 2

Binding to a DataSet DataSource property  Binds a control to the data source  Provides link from mobile application to DataSet Dim dt As DataTable = _ tmpDS.Tables("Info") 'Bind to the list box listBox1.DataSource = dt 'Set column to bind to listBox1.DisplayMember = "Name"

Using a DataGrid Provides a user interface for entire tables in a DataSet Rich formatting capabilities DataGrid is bound to a data source at run time (not design time)

Practice: Binding a Control to a DataSet Binding a control to a DataSet 1 1 Verifying the binding 2 2

Lesson: Using XML Supported XML Classes Building an XmlDocument Reading an XmlDocument

Supported XML Classes XmlTextReader and XmlTextWriter  Forward-only parsers of XML data  Better performance because there is no in-memory caching XmlDocument  Data can be read into the object  After modification, data can be read from the object back to a stream

Building an XmlDocument Private Function BuildXmlDocument() As XmlDocument Dim myXmlDoc As New XmlDocument() Dim NewNode As XmlNode NewNode = myXmlDoc.CreateElement("Project") myXmlDoc.AppendChild(NewNode) NewNode = myXmlDoc.CreateElement("Task") NewNode.InnerText = "Write Code" myXmlDoc.DocumentElement.AppendChild(NewNode) Return myXmlDoc End Function Write Code Write Code

Reading an XmlDocument XmlDocument is an in-memory DOM tree Navigate DOM using properties and methods of XmlNode class Values of nodes can be extracted and manipulated Private Sub DisplayXmlDocument(myXmlDoc As XmlDocument) Dim oNodes As XmlNodeList = _ myXmlDoc.DocumentElement.ChildNodes Dim sbXMLDisplay As New StringBuilder() Dim TaskNode As XmlNode For Each TaskNode In oNodes Dim PropertyNode As XmlNode For Each PropertyNode In TaskNode sbXMLDisplay.Append((PropertyNode.Name + ": " + _ PropertyNode.InnerText + ControlChars.Lf)) Next PropertyNode Next TaskNode MessageBox.Show(sbXMLDisplay.ToString()) End Sub

Practice: Adding an Element to an XmlDocument Add an element to an XmlDocument 1 1 Verify that the element is added 2 2

Lesson: Using SQL Server CE SQL Server CE Storage Architecture Working with SQL Server CE Using SQL Server CE Query Analyzer Using a SQL Server CE Data Connector Filling a DataSet from SQL Server CE Using Parameterized Queries Reading Data Updating SQL Server CE from the DataSet

SQL Server CE Storage Architecture.NET Compact Framework Managed Stack OLE DB for Windows CE Data Provider SQL Server CE QP/Cursor Engine/ES Visual Studio.NET (Visual Basic.NET, C#) ADO.NET SQL Server CE Data Provider.NET Compact Framework runtime Storage Engine/ Replication tracking Server SQL Server 2000 Client Client Agent: Replication and RDA Server Agent: Replication and RDA IIS HTTP

Working with SQL Server CE Available database storage in Pocket PC is limited SQL Server CE 2.0 Features (see list in Student Notes) Visual Studio.NET automatically configures development environment for use with SQL Server CE  SQL Server CE 2.0 is included with the installation of Visual Studio.NET  Must still configure IIS and Windows CE-based device Installing SQL Server CE on the client device  Add a reference to System.Data.SqlServerCe – or –  Manually copy and extract core platform CAB files

Using SQL Server CE Query Analyzer A A B B C C D D Tap to execute a SELECT * FROM Employees statement Tap to execute a SELECT * FROM Employees statement Tap to add a column to the Employees table Tap to add a column to the Employees table Tap to create an index on the Employees table Tap to create an index on the Employees table Tap to drop the Employees table A A B B C C D D

Demonstration: Using the SQL Server CE Query Analyzer

Using a SQL Server CE Data Connector Connection string to SQL Server requires a database provider SqlCeConnString = "Data Source=My Documents\Northwind.sdf" SqlConnString = "Provider=sqloledb; Data Source=London; Initial Catalog=Northwind" Connection string to SQL Server CE is similar, but a database provider is not specified

Filling a DataSet from SQL Server CE Establish a connection Create a data adapter Call the Fill method Dim myAdapter As New SqlCeDataAdapter() myAdapter.TableMappings.Add("Table", "Titles") cn.Open() Dim myCommand As New SqlCeCommand( _ "SELECT * FROM Titles", cn) myCommand.CommandType = CommandType.Text myAdapter.SelectCommand = myCommand Dim ds As New DataSet() myAdapter.Fill(ds)

Using Parameterized Queries Parameterized queries  Have built-in input validation  Execute quicker and are more secure ' Insert data into the table. SQL = "INSERT INTO Titles (TitleID,TitleName) VALUES (?,?)" cmd.CommandText = SQL System.Data.SqlDbType.NChar, 5) System.Data.SqlDbType.NVarChar, 40) = "MSCF1" = "Compact Framework" cmd.ExecuteNonQuery()

Demonstration: Creating a Local Data Store Create a SQL Server CE table Populate the table

Reading Data The ExecuteReader method runs the SQL or stored procedure and returns a DataReader object The Read method moves the DataReader to the next record Read must be called before data access methods are used Dim reader As _ System.Data.SqlServerCe.SqlCeDataReader = _ cmdTxt.ExecuteReader() While reader.Read() MessageBox.Show(reader.GetString(0)) End While

Updating SQL Server CE from the DataSet Save new or modified DataSet data to SQL Server CE Update method updates the SQL Server CE table with changes made in the DataSet myConn.Open() Dim custDS As New DataSet() myDataAdapter.Fill(custDS) 'code to modify data in dataset here myDataAdapter.Update(custDS, myTableName) myConn.Close()

Review Using DataSets Using XML Using SQL Server CE

Lab 3: Working with Local Data Exercise 1: Reading an XML File into a DataSet Exercise 2: Appending Data to the XML File Exercise 3: Saving Data to a SQL Server CE Table