“Brian Noyes’ writing style easily captures your attention as he elaborates on all aspects of data binding in his book. He has a refreshingly clear and crisp delivery as he starts each chapter with a simple tour of each topic, and then leads you into practical concerns for sound practices and extensibility opportunities. Most importantly, as Brian explains approaches to data-binding architecture, patterns of usage, the value of data sets, binding controls and the rest, he always describes how he reaches his recommendations on the topic. This book is perfect for newcomers to .NET 2.0, but also for those that have some experience. Anyone who cares about data in their applications (okay, that should be almost everyone) is guaranteed to learn something new and useful by reading Brian’s book.”
—Michele Leroux Bustamante, IDesign chief architect, Microsoft regional director, and MVP
“Brian has saved me a lot of time. I’m writing The Hitchhiker’s Guide to Visual Studio and SQL Server 2005 (7th Edition) and I’m not going to have to cover data binding nearly as deeply because Brian has done it for me. His book gets right to the meat of the subject and makes data binding look easy. I was also pleased to see that the book focuses on the misunderstood and under-applied Windows Forms architecture. It’s a must-read for anyone trying to make their application more interactive and to leverage the new Visual Studio 2005 technology. I’m planning to point my readers to this resource when they need an in-depth treatment of data binding.”
—William Vaughn, president, Beta V Corporation
“Data binding has finally come of age in Windows applications. Back in the Visual Studio 6.0 days, I ignored data binding completely and wrote my own repetitive code to encapsulate my business logic. With Visual Studio 2005, we finally have a robust and compelling data-binding technology. To ignore it today would make you inefficient and put you behind the curve. Brian delivers a clear and concise discussion of a core topic of development for Windows today. A combination of an easy-to-follow conversational yet technical tone, excellent examples, and solid explanations make this a must-read for any developer writing for Windows or learning to write for Windows.”
—Stephen Forte, chief technical officer, Corzen Inc.
“This book provides a clear, readable, and in-depth treatment of data binding, with detailed discussions of best practices in the presentation and use of data. Brian communicates his knowledge on the mechanics of data binding to give the low-level understanding that makes all the difference when building sophisticated applications and troubleshooting difficult problems. Effective data binding can enormously reduce the amount of code in your applications and will allow new levels of sophistication in your development. Read this book.”
—Jonathan Cogley, chief executive officer, Thycotic, ASPInsider, and C# MVP
“The .NET Framework 2.0, Visual Studio .NET 2005, and Windows Forms 2.0 incorporate the most powerful data-binding platform yet, and absolutely need a book like this to expose it. Brian’s extensive data-binding knowledge and experience shine through as he comprehensively explores its many facets, starting with the fundamentals before tackling a wide variety of real-world scenarios. I’ve always thought a data-binding book was necessary, and I’m glad Brian found the time to write his.”
—Michael Weinhardt, freelance author and application developer
“ Data Binding with Windows Forms 2.0 earns a gold star and a prized place in my development book library. Brian is an exceptional teacher of technology, best practices, and technique. He continues to educate at every presentation I attend; his book carries that quality to paper. I found this book to be highly informative and full of all the important steps and examples necessary to learn this technology. In this book, Brian demonstrates a firm grasp on the concepts and I really enjoy his efforts to promote best practices at every chance. Definitively a cover-to-cover read.”
—Randy Hayes, president, Expert Network Solutions, Inc.
“Brian’s direct and well-organized presentation makes this much misunderstood topic finally understandable.”
—Sahil Malik, author of Pro ADO.NET 2.0 and C# MVP
Data binding is the most important part of many business applications—and one of the most difficult things to understand. Data Binding with Windows Forms 2.0 is the first book to focus on this crucial area of development. It will quickly get you up to speed on binding data sources to Windows Forms components. The book contains clear examples in C# that work with SQL Server 2000 and SQL Server 2005. Visual Basic .NET examples are available on the book’s Web site.
Brian Noyes, leading consultant and speaker on .NET programming, teaches you both the theory and practice of data binding and provides numerous samples ready to run in Visual Studio 2005.
From his in-depth coverage, you’ll learn how to
"synopsis" may belong to another edition of this title.
Brian Noyes is a software architect, trainer, writer, and speaker with IDesign (www.idesign.net), a premier .NET architecture and design consulting and training company. He has been developing software systems for more than fifteen years, speaks at many major software conferences around the world, and writes for a variety of software journals and magazines.
When I first started discussing this book with the editors at Addison-Wesley, I was a little skeptical. My gut reaction was, “Will anyone need a whole book focused on data binding?” I mean, Windows Forms is just GUI stuff, right? You drag this, you drop that, you hook up a few event handlers, and you move on to build the rest of your enterprise application—all the middle-tier goo that ties your head in knots.
As I thought more about it, I realized that a significant percentage of the work that people do in Windows Forms applications is centered around data binding, and most of the problems developers encounter are related to getting data-binding scenarios to work correctly. Add to that the multitude of new capabilities in Windows Forms 2.0 and Visual Studio 2005 related to data binding, and I quickly became convinced that this book would be a good idea. Hopefully you will agree after you have finished reading it.
Data binding is a powerful capability that has finally matured in Windows Forms 2.0 through the capabilities in the .NET Framework classes, combined with the rich designer support provided by Visual Studio 2005. By using data binding properly, you can save yourself from writing a lot of unnecessary code, provide your users a rich interactive experience for working with data that functions well, and produce code that is easy to maintain. To get it working correctly across a variety of use cases, you need to know more than how to set a few properties on controls—you need to understand what is going on under the hood, especially if you want tosupport complex scenarios that require going beyond the basic capabilities of the data-binding components in the .NET Framework.
Due to the growth of smart client architecture, Windows Forms applications are becoming more prominent in business systems. Web browser-based applications leave a lot to be desired; they cannot support many of today’s common scenarios. They don’t harness the capabilities of the client machine, and they are constrained by the request-response model of browser-based applications and the connectivity issues that surround them. So the importance of being able to code complex data application scenarios in Windows Forms is growing, and luckily the capabilities in .NET services are rapidly maturing to keep pace.
Who Should Read This Book?
The primary audience for this book is intermediate to advanced Windows Forms developers who want to learn about the new data-binding features in Windows Forms 2.0 and refine their coding practices for data-bound applications. This book dives deep into advanced features of the data-binding mechanisms in Windows Forms, data-bound controls, working with data sources, and creating custom data-bound objects and collections. If you spend a significant amount of time working with data in Windows Forms applications, then this book is for you.
If you are a beginner Windows Forms developer, this book will help you quickly learn how to support data binding. Many of the features in Windows Forms 2.0 take developers through wizards and designer features that are helpful for beginning programmers, and you will learn about those features in this book. In addition, Appendixes C and D are geared for beginner programmers to get up to speed on the basics of Windows Forms and data access.
Conventions
Developing applications is more about tools and less about code. However, there is a lot of code in this book, and I have adopted some common conventions to help make things easier. References to classes, variables, namespaces, and other artifacts that manifest themselves in code are in a monospace font; this helps you distinguish an instance of the DataSet class from a conceptual discussion of data sets. Short code listings are presented inline within the text using a different monospace font.
Longer listings use a similar font, but are identified with listing numbers, for example, Listing 4.1. Within code listings, bold highlights particularly relevant portions of the code, especially “evolving code.” When I remove details that aren’t relevant to a discussion, you’ll see a comment with an ellipsis (//...). This means that more code is needed to complete the example or more code generated by the designer exists, but you don’t need it to understand the concept. On occasion, explanatory comments show context.
I use a conversational tone to discuss the kinds of objects you deal with in data-binding scenarios, for example, when describing the DataSet class in this book. However, much of the time when discussing data sets I am not talking about an instance of a DataSet class, but of an instance of a derived typed DataSet class. Although it would still be technically correct to refer to that class as a DataSet because it “is a” DataSet through inheritance, I find it annoying when too many words are called out as a code artifacts. So, when something really is a code artifact and can only be discussed correctly in that context, it’s set in the monospace font. I favor the terms data set, datatable, and table adapter when discussing concepts surrounding those types of objects, and reserve DataSet, DataTable, and CustomersTableAdapter for citing a specific class type or instance, and the capabilities defined by that code artifact.
Discussing components and controls can also be confusing, depending on how precise you want to be with your language. Technically, all controls in Windows Forms are components, because the Control class derives from the Component class. Many of the concepts surrounding data binding apply to both components, such as the BindingSource component discussed in depth in this book, and controls, such as a DataGridView control. Unfortunately, many people think of components as nonvisual objects that are used by your form and controls as objects that have a visual rendering on your forms. To avoid having to say controls and components ad nauseam, when I discuss a concept that applies to both nonvisual components and controls, I simply say components. So when you see components, think “this applies to controls as well, because they inherit from components.”
System Requirements
This book was written with the code base of .NET 2.0 and Visual Studio 2005 over the course of Beta 1, several Community Technical Previews, and ultimately Beta 2. The code presented in this book runs with Beta 2. I worked closely with the Windows Client product team at Microsoft, and there are no feature changes planned between Beta 2 and product release. However, some minor syntax may change between production and the release of .NET 2.0. If they do affect the code or concepts, I will provide corrections through the Web site for the book (www.softinsight.com/databindingbook), as well as updated code that will run on Visual Studio 2005 once it is released.
If you plan to run the samples available on the book’s Web site, or the walkthroughs and code listings in the book, you will need Visual Studio 2005 installed on your machine, and you will need access to a SQL Server 2000 or 2005 database server on which the Northwind sample database has been installed. Additionally, you will need to have permissions on that database to create new databases for some of the samples.
There are multiple versions of Visual Studio 2005 to choose from. All of the features discussed in this book even work in the Express versions of Visual Studio 2005, which are free. You can develop all of the samples in this book in Visual C# 2005 Express or Visual Basic 2005 Express with SQL Server 2005 Express, but because Express versions of Visual Studio don’t support data connections using server paths (they only support file path-based connections to SQL Express databases), you will have to create the sample databases and data in SQL Express, and then alter the connection strings and the way you set up connections based in Express.
The samples and scripts included in the book assume you are working on a machine with a standard, professional, or enterprise version of Visual Studio 2005 installed, along with a default instance of either SQL Server 2000 or 2005 on your local machine. To run the samples without that configuration will require modifying the connection string settings for all of the samples that run against a database. The modifications needed are discussed on the book’s Web site, and the differences in connection strings are highlighted in many places in the sample code.
Additionally, Northwind doesn’t ship with SQL Server 2005, but is available as a separate installable download that will work with SQL Server 2005 from MSDN Downloads at www.microsoft.com/downloads/details.aspx? FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&displaylang=en. The download provides scripts and MDF files that can be attached to SQL Server 2005 or used with SQL Server 2005 Express.
Choice of Language
I chose to write this book in C#. The download code is available in both C# and Visual Basic code. It is a fact of life that there will continue to be a mix of C# and Visual Basic available in articles, books, and samples for a long time to come. Even though I prefer C# myself, I am not a language bigot and feel Visual Basic is a solid choice for developers who have a strong background in earlier versions of Visual Basic.
I firmly believe that to be an effective .NET developer, you need to be able to read code from either language, even if you spend most of your time with one. If you aren’t already comfortable reading C# code, I encourageyou to use this opportunity to get comfortable reading it. It will expand your horizons in terms of the amount of reference material that is available to you, it may help you in your job, and it will give you bragging rights over the many silly and close-minded C# developers who cannot read Visual Basic.
Coding Standards
Yes, I have coding standards, and you should too. It is as simple as that, but unfortunately not done nearly enough by development organizations. Coding standards are an important tool in making sure that code is bug free, but they are even more essential for making sure that your code base is maintainable. Code written by one developer on your team should look like the code written by all the other developers so that it can be maintained and extended if necessary. Code reviews go hand-in-hand with your coding standard and are also something that should be a regular part of your development process.
We have an excellent coding standard at IDesign, which can be downloaded from our site at www.idesign.net. You can use as is, or you can use it to develop your own coding standard. Our standard includes a lot of information that goes beyond simple syntax; it has a lot of best practices for .NET development and design.
For the code presented in this book, I used the IDesign coding standard for naming member variables, properties, methods, and event handlers. Any member of a class, whether just a variable or a control on a form, is given a prefix of m_ and PascalCasing is used for the rest of the name. This is different from the Microsoft standard (which varies somewhat across different product teams), and that is okay. You can use whatever standard you want, as long as you are consistent. I won’t go into the arguments and justifications of coding standard here, but I want to short-circuit any complaints or e-mails that might result.
You will see code snippets where this convention isn’t followed (when I am discussing designer-generated code), because the naming conventions generated by the designer differ from our coding standard. So when discussing the raw code generated by the designer, I will demonstrate theway they generate the code; when I am writing code or focusing on other aspects of the code, I will rename the things generated by the designer to comply with IDesign coding standard.
Code First Versus Design Features First
One of the hardest decisions I had to make when writing this book was the order in which to present the concepts: Should I start by discussing code that you can write by hand to get things working in an application, or should I start by walking through all the different combinations of design features in Visual Studio that will write the code for you?
You can get a lot of data binding done through a combination of drag-and-drop interactions in the Visual Studio designer and by setting properties for objects on a form in the Properties window and other windows. When coding production applications, the Visual Studio designer is where you will start 90 percent of the time. Ultimately, those interactions are just having the designer write the code so that you don’t have to. This allows applications to be written much faster and helps figure out how to get data-binding scenarios working even if you don’t really understand the code that is being generated.
If this book’s goal were to cover more introductory level concepts across a wider scope of topics, then sticking to the designer with a little bit of code explanation would be sufficient. However, my goal is to provide a deep technical tutorial on all aspects of Windows Forms data binding for developers who want to tackle complex scenarios that go beyond the designers. Whenever you thoroughly want to understand what is going on, you need to really think about things at the code level, not at the level where the designer, wizards, and windows in Visual Studio are doing magic things for you.
As a result, I chose to tackle things from a code-first perspective. As you progress through the book, for most common scenarios there are ways to get the Visual Studio designers to write most or all of the code for you. But to maintain that code and to go beyond those common scenarios, you also need to be able to write that code by hand (if need be), and know what all the right pieces and parts are to hook together. The chapters are arrangedto first introduce a concept and to show you the raw code that enables you to get that concept working. Then, if there’s a corresponding designer way of getting that code written, that’s covered next.
For example, Chapters 3 and 4 describe data-binding mechanisms in Windows Forms and how to write the code to hook up controls to data sources. Then Chapter 5 shows how to use the Data Sources window to write a lot of that code for you. If you find it easier to learn by seeing things through the designer first and then unraveling the code, you might want to read the chapters and sections focused on the designer features first, and then return to previous sections to understand the code that was written on your behalf.
Northwind—The Database That Will Never Die
To show examples of data binding, you need some data to work with. One approach is to create new databases with new data in them to use in examples. While that may provide more interesting data for the samples, it has the downside of requiring you to learn a new schema and to set up those data sources on your machine to try out the demos. Because most interesting data usually belongs to someone, to avoid having to worry a...
"About this title" may belong to another edition of this title.
US$ 3.75 shipping within U.S.A.
Destination, rates & speedsSeller: HPB-Red, Dallas, TX, U.S.A.
Paperback. Condition: Good. Connecting readers with great books since 1972! Used textbooks may not include companion materials such as access codes, etc. May have some wear or writing/highlighting. We ship orders daily and Customer Service is our top priority! Seller Inventory # S_328569605
Quantity: 1 available
Seller: Better World Books: West, Reno, NV, U.S.A.
Condition: Good. Used book that is in clean, average condition without any missing pages. Seller Inventory # 4516810-6
Quantity: 1 available
Seller: SecondSale, Montgomery, IL, U.S.A.
Condition: Very Good. Item in very good condition! Textbooks may not include supplemental items i.e. CDs, access codes etc. Seller Inventory # 00081976978
Quantity: 2 available
Seller: SecondSale, Montgomery, IL, U.S.A.
Condition: Good. Item in good condition. Textbooks may not include supplemental items i.e. CDs, access codes etc. Seller Inventory # 00085205419
Quantity: 1 available
Seller: ThriftBooks-Atlanta, AUSTELL, GA, U.S.A.
Paperback. Condition: Good. No Jacket. Pages can have notes/highlighting. Spine may show signs of wear. ~ ThriftBooks: Read More, Spend Less 2.35. Seller Inventory # G032126892XI3N00
Quantity: 1 available
Seller: ThriftBooks-Dallas, Dallas, TX, U.S.A.
Paperback. Condition: Very Good. No Jacket. May have limited writing in cover pages. Pages are unmarked. ~ ThriftBooks: Read More, Spend Less 2.35. Seller Inventory # G032126892XI4N00
Quantity: 1 available
Seller: AwesomeBooks, Wallingford, United Kingdom
Paperback. Condition: Very Good. Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NET (Microsoft .Net Development) This book is in very good condition and will be shipped within 24 hours of ordering. The cover may have some limited signs of wear but the pages are clean, intact and the spine remains undamaged. This book has clearly been well maintained and looked after thus far. Money back guarantee if you are not satisfied. See all our books here, order more than 1 book and get discounted shipping. Seller Inventory # 7719-9780321268921
Quantity: 1 available
Seller: medimops, Berlin, Germany
Condition: good. Befriedigend/Good: Durchschnittlich erhaltenes Buch bzw. Schutzumschlag mit Gebrauchsspuren, aber vollständigen Seiten. / Describes the average WORN book or dust jacket that has all the pages present. Seller Inventory # M0032126892X-G
Quantity: 1 available
Seller: Bahamut Media, Reading, United Kingdom
Paperback. Condition: Very Good. This book is in very good condition and will be shipped within 24 hours of ordering. The cover may have some limited signs of wear but the pages are clean, intact and the spine remains undamaged. This book has clearly been well maintained and looked after thus far. Money back guarantee if you are not satisfied. See all our books here, order more than 1 book and get discounted shipping. Seller Inventory # 6545-9780321268921
Quantity: 1 available
Seller: WeBuyBooks, Rossendale, LANCS, United Kingdom
Condition: Good. Most items will be dispatched the same or the next working day. A copy that has been read but remains in clean condition. All of the pages are intact and the cover is intact and the spine may show signs of wear. The book may have minor markings which are not specifically mentioned. Seller Inventory # wbb0023706412
Quantity: 1 available