More advanced examples for the impatient "newby"

T

Ted

Well, I've taken poetic license with "newby" having been programming
for more than a couple dozen years, but I have recently started
studying .NET and ADO.NET, leveraging my experience with other
frameworks such as Borland's VCL, and MS' MFC, and technologies such as
ADO and MDAC, to speed things up.

I have the professional edition of Visual Studio 2005, with MS SQL
Server 2005, and I downloaded and installed ADO.NET 3, the relevant SDK
and extensions to Visual Studio for it.

I intend to experiment with ADO.NET with both a windows forms
application and a web application using ASP.NET.

With my readings so far, I see only simple examples where the master
control (either a text box or a combo box) determines what is seen in a
details grid.

The example I want to use in my experiments is a recipe management
database. The user's user ID will be a parameter in all queries. But
there will be several combo boxes for "Cuisine type" (e.g. Thai,
Mandarin, French, &c.), author (e.g. the user's name, some other
author's name), kind of dish (breakfast, lunch, entrez, appetiser,
desert), possibly with subtypes (e.g. for deserts, cake, pie pudding,
&c.). Some of these combo boxes will have a default value and require
selection of either the default or one other item in the combo box.
Others will allow a NULL value, and if the user decides there should be
a value other than NULL, he or she is constrained to select from the
items in the combo box. The author, for example, might be NULL, to
indicate the recipe may be an old family recipe or a recipe for which
the author is unknown. I guess this is simpler than some cases in that
the user will not be able to type entries into the fields, except for
the author, for which I'll need a validator. OTOH, it is more complex
in that the entries in the combo boxes do NOT affect in any way the
possible choices in any of the other combo boxes. The question I'm
wrestling with is how to use such a collection of controls to manage
what is shown in (in my case) a pair of details grids (one for
ingredients and another for instructions for a given recipe).

Can anyone provide an example, or an URL to a page that gives an
example, that shows how to do this?

The second example I am looking for is how to use a combo box tied to
one table as an editor for the cells in one column of the gridview tied
to another. For example, for the grid representing the ingredients
used in a recipe, the second last column will be a number representing
a quantity and the last column will be units of measure such as grams,
kilograms, ounces, pounds, teaspoons, table spoons, &c. Of course, the
number of possible units is limited, and should be selected from a
combo box rather than entered by the user typing (with all the related
potential sources of error such as typos). But to make things more
interesting, I want to give the user the option of selecting what
system of units (cgs, SI, Imperial) will be used both for entering and
for viewing a recipe, by default but with the option of changing the
system of units used for a given recipe (so a user prefering to use
metric can enter a recipe provided in imperial units and have my
program automatically convert it to metric). After all, a person most
familiar with metric might have, for whatever reason, a cookbook in
which all recipes are provided with imperial units.

Like I said, it is trivially easy for me to get applications similar to
the examples I have found (both in the provided MS documentation and
the multitude of books I have bought) to work, but their extension to
situations like what I describe above is not obvious.

I had thought about doing most of this in code, but I want to know if
there is an easy way to accomplish this using Visual Studio 2005's form
designer before I start writing n-factorial parameterized SQL
statements or a function to create them at run time.

Pointers(URLS) to more useful examples of using ADO.NET2/3 would be
greatly appreciated.

Thanks

Ted
 
E

Earl

You can do all that you want with this interaction between combos and
datagridviews, but the key to success will be the design of your database.
If your tables are not parented correctly or not keyed correctly, then you
will have an infinite number of problems making this work. Assuming the
database is designed correctly, I use the following approach:

1. Set up your typed datasets to perfectly match the database layout (or
portions thereof). Make sure to set your autoincrement and seed to -1.
2. Create a binding source for each table that you will use on that form.
Set the bindingsource datasource to the typed dataset and datamember to the
table.
3. Populate the combos from the database, ensuring that you set a
ValueMember;
4. Populate the dataset tables from the database.
5. Bind the datagridview to the the bindingsource (I only do this AFTER I
have populated the dataset tables).
6. Bind the combos (selectedvalue for ID primary keys and text for natural
PKs) to the same bindingsource.

Now the trick becomes to use your foreign keys in order to populate and
update the datasource. As appropriate, you can pull the keys from the combos
valuemember or from the typed dataset datatables (by using the current row
position). Once you know the FK, you can then call a sproc to populate a
detail grid with the choices applicable to the combo selection or grid
selection. As you build and test the app, use your DataTable analyzer
(often!) to confirm the contents of your datatables, particularly when you
are using multiple FKs in one table.

Incidentally, I do not use the bindingnavigators nor the tableadapters. I
only use the bindingsources to maintain synch between the controls on the
form. When you drag a table onto your typed dataset, the tableadapters are
created for you automatically, but I delete them immediately. My preference
is to use the SqlDataAdapters and the DACW to create my command parameters.
Your mileage may vary.
 
R

RobinS

This has probably been asked and answered before,
but would someone kindly explain to me why you
set the autoincrement and seed to -1 on auto-number
fields in SQLServer? I'd appreciate it.

Thanks,
Robin S.
----------------------------------------
 
E

Earl

Not in the SqlServer. You use the negative autoincrements only as
placeholders in the dataset to ensure you don't collide with a "real"
existing PK. When you submit the Update, the real table will generate the
real autoincrement -- in a positive direction.
 
R

RobinS

Let me make sure I understand. You're talking about
AutoIncrementSeed and AutoIncrementStep on a
typed dataset? I should set those both to -1
after creating my typed dataset, like with the
dataset designer? Do I need to do this when I
create the datasets manually in code?

Thanks,
Robin S.
---------------------
 
W

William \(Bill\) Vaughn

See my article on handling identity.
http://www.betav.com/Files/Content/whitepapers.htm. I discuss this in more
depth in my new book...

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
-----------------------------------------------------------------------------------------------------------------------
 
R

RobinS

Thanks. I will. I appreciate it. I've just read a bunch of .Net
books (I call it powerlearning). I'm not sure I can read another
one just yet, but I'll put yours on my list.

Robin S.
-------------------------
 
T

Ted

RobinS said:
Thanks. I will. I appreciate it. I've just read a bunch of .Net
books (I call it powerlearning). I'm not sure I can read another
one just yet, but I'll put yours on my list.

Hi Robin,

Would you care to list the .NET books you read and give your appraisal
on their utility/quality?

I have bought a number of good books lately, but they deal specifically
with certain technologies (ADO.NET or ASP.NET) or languages (VB, C#).
They seem to give short shrift to .NET per se.

What I have seen so far of .NET, it appears to be just another
application framework, like Borland's VCL or MS' MFC (though a higher
level than MFC, much more lke Borland's VCL).

I hate books with insulting titles, like "Idiot's Guide to 'X'" or "'Y'
for Dummies". I have been programming on a variety of platforms using
a variety of languages and application frameworks for well over two
dozen years and want a good reference that respects that even though
the specific technology described and explained is new to me.

Did you find any books you'd describe as excellent or at least very
good, well above average?

Cheers,

Ted
 
W

William \(Bill\) Vaughn

For years, readers have found my "Hitchhiker's Guides" series don't talk
down to developers. They're designed to help those transitioning from one
Microsoft architecture to another without getting lost in the clutter and
chatter. At this point, I've sold almost 100,000 books and I expect that the
7th edition will be my last. It should be appearing in bookstores in the
next few days. It's already shipping from online sources.

As I've said many times before... I hope it helps.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
-----------------------------------------------------------------------------------------------------------------------
 
E

Earl

I've got two of Bill's books (altho not the latest), and its all helpful
stuff. Beyond that, there are probably only a handful of good books
specifically on ADO.Net (not to be confused with books "generally" on .Net).
Sahil Malik (who posts here) has "Pro ADO.Net 2.0" and David Sceppa, a
Microsoft employee who also posts here has "Programming Microsof ADO.Net 2.0
Core Reference". The O'Reilly book by Bill Hamilton "ADO.Net Cookbook" is
simply superby for specific "how-tos". Finally, most general .Net books have
an ADO.Net section or two in them (including the study guides), although
it's obviously difficult for a book on such a wide topic to give much
in-depth information just on ADO.Net.
 
W

William \(Bill\) Vaughn

Sahil was kind enough to find the time to review and provide feedback for my
latest book. His book has a lot to offer. I've worked with David Sceppa for
a long time--he's a well-recognized expert on the subject (since much of it
reflects his ideas). Both of their books are on my "at arm's reach"
shelf--which only holds about 5 books.

That said, I have found that applications (virtually all applications at
that) have a data access component, but understanding how to open
connections, build Command objects and execute them is not the only skill
one needs to create an effective, efficient, productive application. If the
developer does not understand the DBMS engine (which to choose, how to
deploy it, how to tune it, and more), or if the developer does not
understand how to create an efficient relational database for the DBMS
engine to manage, they are going to be frustrated no matter how well they
understand ADO.NET.

That's what this (entirely) new Hitchhiker's Guide is all about. I started
from scratch to create a place where developers who want to know how to
design a data access application (especially one that accesses SQL Server)
can go. I show what works and what doesn't. I'm not star-struck with
Microsoft's newest technology but I can show you where it's the best choice
available and where it's not.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
-----------------------------------------------------------------------------------------------------------------------
 
S

Sahil Malik [MVP C#]

Thanks Earl.

There is another book name I want to add to the list of "Good data related
books" - Author: Bob Beauchemin.

Ted,

I want to comment a bit on books that go beyond just teaching ADO.NET and
dive into the advanced/weird scenarios. Especially since you are not really
a "newbie".

To tell you the truth, they are hard to cover in a book. A book, be it on
any topic - say physics, assumes a frictionless surface in one example, and
then explains friction on a seperate example - but friction in zero gravity.
A real example involves both friction and gravity (and maybe even
viscosity).

So a book can take 1 of 3 approaches

- Explain only Friction + Gravity: You'll loose half your audience. The 3
computer science majors who cringe in sunlight and like to live in dark and
moist environments, will love the book, but overall the book will be a
dud for the true real world professional who is more focused on solving
problems - than solving the framework.

- Explain Friction, Gravity, and then explain Friction + Gravity: Great
approach, except it will take 3 times as long to write a book, it would be
terribly heavy and bulky, and you run the risk of pissing off your audience
due to too much redundancy.

- Explain Friction, Gravity, and leave Friction + Gravity for blogposts,
articles, newsgroups and frankly consulting. This approach IMO works the
best and most best selling books use this approach.

So without making things too specific, in my book I explained two complex
real world scenarios - Hierarchical updates and an in-depth on transactions.
Besides that, once you have these concepts covered, mixing/matching them
into various permutation combinations is what real world experience is all
about :).

And of course you are not going to please everyone with a single book. :)

So anyway, Bob, David and Bill are brilliant individuals, and all 4 of us
present
the same content really from different points of views/styles/altitude. The
best thing to do is, go to a book store and flip through the contents and
see which one suits your needs better.

Enjoy,

- Sahil Malik [MVP]
http://blah.winsmarts.com
 
R

RobinS

I have read about half a dozen books, and own a couple more.
The two that come straight to mind with your question are
by Francesco Balena.

One is called "Programming Visual Basic 2005: The Language".
He has a version of this book in C# as well. This book *only*
covers the language -- no data, no forms. But it's the first
book I read that explains delegates in such a way that I
really, really get it, and understand what to do with them.
This is not a beginner's book; it helped me to add depth to
the areas I'm already programming in, and helped to learn
about areas I haven't used, like Reflection. I also found
this to be really readable, and I read it from cover to cover.
(That probably makes me weird, but I can live with that.)

The other is "Practical Guidelines and Best Practices
For Visual Basic and Visual C# Developers". I read this
one from cover to cover, too. It has a lot of information
about "this way works better than this other way", and info
about benchmarking. For example, it's better to use multiple
String.Append statements than it is to do
"String.Append a.ToString & "hello" ". I don't agree with
everything in this book (I am following the new guidelines
of naming my controls like ProductTextBox instead of txtProduct),
but it was well worth my time.

The third book I would recommend is Brian Noyes's Data Binding
book. It's in C#, but he provides code downloads in both
C# and VB. I'm a VB programmer, which made this a little
difficult, but on the bright side, I'm a lot better at
reading C# now. ;-) My only problem with this book is that
it's not strictly a "follow this example" book. There's a
lot of "you could do this" kind of stuff in it, and when
he does give examples, he doesn't always tell you all the
stuff you need to do, which I found frustrating, because I
learn by working the examples. He had a lot of stuff about
the DataGridView control, though, and while this concentrates
on Windows Forms, it has a large appendix about WebForms.
Aside from my frustration with it, I learned a lot from
reading it, and it has really added to my databinding
knowledge.

And my last book is "Doing Objects in VB2005" by Deborah
Kurata. I am a long-time VB6 programmer, doing desktop
applications, working mostly by myself, and haven't been
exposed to the n-layer approach because I never learned
how to do it. This book has a chapter on methodology, which
even after 20 years of programming and working directly with
clients will help me gather requirements in the future.
Then it goes on to explain how to set up your business layer,
your data access layer, and your forms, and how to communicate
appropriately between them. It includes how to data bind
your objects and how to write your basic stored procedures
to update your data (SQLServer) and uses Generics to set up
error handling on the forms. You end up developing an entire
MDI application that you can build upon. This really brought
together a bunch of concepts I had heard of but never worked
with and now I really get it. This book is not available yet;
I think it will be out in January. I had the opportunity to
see an advance copy because Deborah is an INETA speaker,
and a Microsoft MVP, and she runs the local .Net User Group
where I live (SF Bay Area).

I also checked out Bill Vaughn's book at Barnes & Noble
yesterday. I didn't read it at length, but I have to admit,
it looks really thorough. I didn't buy it (yet), because
I buy all of my books from amazon because (1) they are
cheaper, and (2) I get "free" 2nd day shipping (because
I joined amazon prime) and (3) I like to read the reviews.
(For grins, check out some of the reviews for Chris Sells'
Windows Forms book). It would not be surprising for me to
end up with Bill's book, though. I don't really need to plug
it here, because he's doing a fine job at that himself. ;-)

Just one more word: I bought a VB Step by Step book, and
it's really, really basic. So I'd probably steer clear of
those unless you wanted something really, really basic.

So what have you read that you really, really liked?

Robin S.
----------------------------------------------
 
R

RobinS

It's already in bookstores. They had 2 copies at Barnes & Noble
where I live. Why will it be your last?

Robin S.
-------------------------------------------
 
R

RobinS

Do you talk at all about data binding in your book?

Robin S
--------------------------------
 
W

William \(Bill\) Vaughn

Why my last? It took over two years to write. During that time over 1000
pages of content were bottled up and could not be revealed. It's not fair
for me or for those that need the information I had gathered. Over 7 months
of that time the book was held captive by the publisher as they hand-etched
the plates used to print it (or so it seemed). It's simply too expensive to
write a book that might have a shelf life of three years.

EBooks make more sense. I can write one in about a month (or so) and publish
it immediately. It remains to be seen if readers will be as willing to buy
bits instead of paper. Sadly, I expect the forest of trees shown on the
cover of my book (or those just like them) were those cut down to print
it... ;(
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
-----------------------------------------------------------------------------------------------------------------------
 
W

William \(Bill\) Vaughn

I discuss data binding, but I too like the Noyes book focused entirely on
data binding. It sits on my "at arms reach" shelf. I tried to boil down the
complexity quite a bit to a few nuggets to make it easier to understand.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
-----------------------------------------------------------------------------------------------------------------------
 
T

Ted

William said:
Why my last? It took over two years to write. During that time over 1000
pages of content were bottled up and could not be revealed. It's not fair
for me or for those that need the information I had gathered. Over 7 months
of that time the book was held captive by the publisher as they hand-etched
the plates used to print it (or so it seemed). It's simply too expensive to
write a book that might have a shelf life of three years.

EBooks make more sense. I can write one in about a month (or so) and publish
it immediately. It remains to be seen if readers will be as willing to buy
bits instead of paper. Sadly, I expect the forest of trees shown on the
cover of my book (or those just like them) were those cut down to print
it... ;(
--
That relates to another project I have in mind, and have done some
experimenting on. I think the idea of a virtual library, to which
readers would gain access by paying an annual fee of, say, $50. It is
not too hard to design the web interface in such a way as to provide
better protection of copy-righted material than does print and paper.
I have spent some time working in south asia and have seen whole books
photocopied. It is bad enough that many publishers produce special
versions, made of much cheaper materials, specifically for south asia
and sold at a tiny price relative to the versions sold in north
america. But some of the best titles are not available there, except
as imports of the versions sold here.

Anyway, I expect there would be many people who'd pay $50 a year for
access to a virtual library instead of, or perhaps in addition to,
conventional hardcopy books.

It may be just a matter of time. I can even see how publishers could
profit from it, by using a virtual library as a means of marketing
their books. After all, while I do read a technical reference online,
there is much to be said for having it in hardcopy in my library. And,
there are so many titles out there, it can be a challenge to examine
them all to determine which best fits my needs, especially when there
aren't any bookstores within 100km (about 60 miles) that stock even one
good technical reference. All of the good technical references I have
bought over the past few years have been bought online, and thus were a
bit of a gamble since I didn't know the work of the author. I have
seen a number of interesting titles, with equally interesting
descriptions, but I have refrained from buying them because they're so
expensive that the risk of getting what turns out to be junk is too
great.

Cheers,

Ted
 
T

Ted

Hi Sahil

I appreciate this. I'd also say I understand the challenges of writing
a good book since I am an experienced scientist and educator, as well
as having experience developing software. As an educator, I have
taught both students fresh out of secondary school and graduate
students. Books for the former are common, though too many are too
insulting to the reader to be recommended. Good books for the latter
are extremely rare, probably for the reasons you cite, among a few
others. Hence, I have always relied on articles in the peer reviewed
scientific literature and my own experience for the latter.

Alas, your advice to browse at the bookstore isn't practicable for me
since there isn't a bookstore within 100 km of me that stocks even one
good technical reference.

Thanks again

Ted
 
T

Ted

Hi Robin,

I have Balena's book on VB 2005, as well as Marshall's book on C# 2005
(both language references), and Esposito's books on ASP.NET 2.0.
Petzold's book on programming Windows Forms, and the corresponding book
on web forms (I forget the author's name), are also pretty good.

One of my interests is a comparison of languages and it is interesting
to see some convergence among them (such as the addition of generics to
Java, VB and C# - though I don't know enough about the history of C# to
know if it had generics from the beginning.

I also have Sceppa's book on ADO.NET. It is very good too.

As for what I really REALLY liked, top of the list would have to
include Knuth's classic multivolume work (but that was long long ago),
Stroustrup's Design and Evolution of C++, and Lippman's "Inside the C++
Object Model".

I would LOVE to see similar books talking about the design and
evolution and object models of other languages such as Java, VB, C#,
FORTRAN, Perl, PHP, and Smalltalk to name a few. And I'd love to see a
book that follows on from Coplien's Multiparadigm Development,
discussion a variety of programming paradigms (structured programming,
procedural programming, object oriented programming, generic
programming, template metaprogramming, &c.) along with consideration of
how well each can be used with each of such a range of languages (as
that listed above).

Cheers,

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top