The Windows Forms DataGrid A Complex-Bound.NET GUI Control Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD.

Slides:



Advertisements
Similar presentations
Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
Advertisements

1.NET Web Forms DataGrid © 2002 by Jerry Post. 2 Data Grid Has Many Uses  The grid uses HTML tables to display multiple rows of data. It is flexible.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
SQL Server on a Cluster Experiences Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
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.
VB.NET Database Tools ISYS Net Applications OLE DB Provider OLE DB Data Source OLE DB Provider ODBC Data Source SQL Server Data Source SQL Server.Net.
Introduction to Data Adapter. A Simplified View of ADO.Net Objects Ado.Net Data Provider Connection Adapter Command Reader Dataset Data Consumer WinForm.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
VB.NET Database Access ISYS 812. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
VB.NET Database Tools ISYS 573. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
EGR 141 Computer Problem Solving in Engineering and Computer Science Interfacing with a Database in Visual Basic.NET 2005.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS546.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Introduction to ADO.Net and Visual Studio Database Tools
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Some Basic Database Terminology
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
9-1 Chapter 9 Working with Databases in VB.NET. 9-2 Learning Objectives Understand how databases are used to store business data and how they differ from.
Databases and LINQ Visual Basic 2010 How to Program 1.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
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.
1 Lesson 6 — Database Programming Microsoft Visual Basic.NET, Introduction to Programming.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last.
Navigating database with windows forms.. Tiered applications  Provide a means to develop many presentations of the same app  Makes changes to the back.
Advanced Visual Basic th Edition Chapter 3: Using SQL Server Databases (c) 2007 Pearson Education Inc. All rights reserved. You may modify and copy.
1 Databound Controls. 2 Objectives You will be able to use design time data binding to display and update SQL Server database data without writing any.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Thirteen Working with Access Databases and LINQ.
CHAPTER EIGHT Accessing Data Processing Databases.
Working with GridView Control: Adding Columns. Adding Buttons to a Bound GridView: 1. Drag the WebProduct table from Data connection to a page 2. Demo.
ASP.NET - accessing the database - datareader vs dataset - datagrid vs datalist - brief look at web matrix.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Binding Basics.
Module 4: Building DataSets. Overview Working in a Disconnected Environment Building DataSets and DataTables Binding and Saving a DataSet Defining Data.
Windows Forms Navigating database with windows forms.
Using Adapter Wizard ISYS 512. Data Adapter Wizard – 2 nd Level of Using ADO.Net Configure Data Adapter and generating a dataset: –From the Data tab of.
ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
TRAINING SESSIONS.NET Controls.  Standard Controls  Label  Textbox  Checkbox  Button, Image Button, Image control  Radio Button  Literal  Hyperlink.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Tutorial 101 Variable Arrays A group of variables that have the same name and data type and are related in some way Can have as many as 60 dimensions.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
1 Database Programming with ADO.NET Kashef Mughal.
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.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
Creating SQL Database file And Displaying a Database Table in a DataGridView.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Visual Basic 2010 How to Program
Basic Database Concepts
ADO.NET Accessing Databases in VS.NET
test slide
VB.NET Using Database.
Database Applications
Chapter 10 Accessing Database Files
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

The Windows Forms DataGrid A Complex-Bound.NET GUI Control Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT C ONSULTING PTY LTD Simple vs Complex Binding simple binding : binding a control to a single data column. A TextBox is an example of a control that can be simply bound. complex binding : binding more than one column to a single control. The DataGrid is an example of a control that can be complexly bound.

Fitzsimon IT C ONSULTING PTY LTD Retrieving and Updating Data Add a new connection (in Server Explorer, right-click Data Connections and choose Add Connection) Connect the form to the tables (in Server Explorer, drag table icons to the form. An OleDbDataAdapter is created for each table, and an OleDbConnection to the database is also added)

Fitzsimon IT C ONSULTING PTY LTD Demo Northwind.mdb Three tables: Customers, Orders, Order Details Display in DataGrid Update in DataGrid

Fitzsimon IT C ONSULTING PTY LTD Danger, Will Robinson! The three tables are related in the database, but no relations exist between them in the DataSet. Editing in the DataGrid can create inconsistent data in the DataSet. dataAdapter.Update will fail Avoid this by adding DataRelation objects to your DataSet

Fitzsimon IT C ONSULTING PTY LTD Proper Case Column Headers When setting a DataGrid’s data source programmatically, cannot assign column header names at design time. The DataGrid uses the recordset’s column names. Often these recordset column names may be confusing, not to mention unprofessional looking. Work-around: use alias field names in the SQL statement for the underlying data source. E.g., in a SQL statement, instead of: SELECT pub_id, pub_name FROM pubs Use: SELECT pub_id AS ID, pub_name AS Publisher FROM pubs

Fitzsimon IT C ONSULTING PTY LTD Data binding with a collection A collection can be populated with simple data, such as strings, and bound to a list box control. Dim objCollection As New Collection() objCollection.Add("Value 1") objCollection.Add("Value 2") objCollection.Add("Value 3") objCollection.Add("Value 4") ListBox1.DataSource = objCollection

Fitzsimon IT C ONSULTING PTY LTD Custom objects bound directly to a DataGrid control Create a new class Public Class MyData Private cstrValue1 As String Private cstrValue2 As String Public Sub New(ByVal Value1 As String, ByVal Value2 As String) cstrValue1 = Value1 cstrValue2 = Value2 End Sub Public Property Value1() As String Get Return cstrValue1 End Get Set(ByVal Value As String) cstrValue1 = Value End Set End Property Public Property Value2() As String Get Return cstrValue2 End Get Set(ByVal Value As String) cstrValue2 = Value End Set End Property End Class

Fitzsimon IT C ONSULTING PTY LTD Custom objects bound directly to a DataGrid control Next, add a data grid control to the form, and add the following code to the form Load event: Dim objCollection As New Collection() objCollection.Add(New MyData("Value 1", "Test 1")) objCollection.Add(New MyData("Value 2", "Test 2")) objCollection.Add(New MyData("Value 3", "Test 3")) objCollection.Add(New MyData("Value 4", "Test 4")) DataGrid1.DataSource = objCollection

Fitzsimon IT C ONSULTING PTY LTD

Questions Mike Fitzsimon Sample code & this ppt available from