p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Visual Basic 2010 Programmer's Reference (http://p2p.wrox.com/forumdisplay.php?f=551)
-   -   CH 20 Database Controls (http://p2p.wrox.com/showthread.php?t=84200)

cpfuller June 29th, 2011 05:31 PM

CH 20 Database Controls
I'm not quite sure how to make this question simple. I am an old clipper/dbase programmer trying to get back into database programming using visual basic. It seems to me that the creation of new ways of accomplishing database access are proceeding at warp speed. ADO.net is evolving into LINQ and LINQ is evolving into Entity Framework etc. almost faster than the books can be published. In chapter 20 Rod talks about database access and database controls. In the first part of the chapter Rod describes how to use Visual Studio wizards etc to create connections, datasets, binding sources, and binding navigators. That's pretty cool within 5 minutes I can be viewing data and editing it and I haven't written very much code. Then in the section titled OTHER DATA OBJECTS beginning on page 430 his opening sentence is "If you want a simple program that can display and modify data, then the solution described in the previous sections may be good enough."

I want to learn the method that will allow me to write a complex POS system but I like easy. I don't mind learning to code it myself and in fact I am such a control freak I probably prefer it. What I don't want to do is spend a bunch of time and energy learning an old way of doing something when the simply way of yesterday will be the robust way of tomorrow.

I guess my question is as follows:

Is it necessary to write my own data access code or have the "simple" tools evolved enough that they can be trusted in robust applications and I need to just learn how to use them?

I hope someone can make sense of this.


Rod Stephens June 30th, 2011 11:13 AM

I've seen studies that claim 80% or more of all Visual Basic involve a database, and I believe it. Because there's so much market (and money) at stake, Microsoft can't pick something and leave it alone. There have been so many "latest and greatest" database tools over the years that I can't even remember them any more.

I'm a bit of a control freak, too, when it comes to databases so many of the programs I've written don't use the latest easy method. Instead they use connection objects to load data and then process it more directly. It's a bit more work but you get a lot more control over exactly what's happening. If you package the work in nice routines, it's pretty reliable and reusable.

Also the standard solutions tend to have models that don't work well with some of the applications I've worked on. For example, a recordset or dataset takes a snapshot of a big piece of the database. That works okay if you're the only user but can be a problem if there are lots of users working on the same tables. Then you need to build your own synchronization tools. It's not terribly hard to do something like set a field in a record to indicate that a particular user is working on it but things like data binding and Entity Framework don't do it for you.

cpfuller July 1st, 2011 06:01 PM

If you don't use datasets what do you use
Rod thanks for responding. If you don't read information from the database into a dataset what do you do. One small app I wrote starts out with a textbox for data input. My code takes that input and builds a query that loads all matching info into a dataset. Example the publisher prefix for wrox in the isbn is 0-470- My program would query my book database returning all records that started with 0-470 which would be all the wrox titles in my database. It loads into a dataset that I can then page through or view in a grid. I'm new to this so I am trying to determine what tools to use were. Thanks again for your time. I do have several of your books they are just not at the house I am staying in.


Rod Stephens July 3rd, 2011 10:50 AM

That should work.

Usually I read data into a DataSet or Recordset, I just don't always use data binding to display and edit it. For example, suppose you bind a DataSet to a DataGridView and let the user edit the data there. That works fine if it's a single user system but the changes remain in the DataSet and don't go back to the database until you save all of the changes. If there's more than one user, how do you know you're not making duplicate or conflicting changes to the data?

In that case, I would make the user select a record to edit. Then either use the database's locking mechanism to lock it or add a LockedBy field to the table so the code can "lock" the data logically. That way two users can't edit the same data at the same time. You can also see who has a record locked if you need to.

All times are GMT -4. The time now is 11:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.