View Single Post
  #2 (permalink)  
Old October 19th, 2013, 01:16 PM
Rod Stephens's Avatar
Rod Stephens Rod Stephens is offline
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hi John,

Dragging-and-dropping is really intended only to build a quick and easy database program. It's not really intended for complicated things like this (although I know it's not all that complicated). There are probably ways to do this but it may be tricky.

You could try this:
  • In the component tray below the form in the form designer, right-click the table adapter manager and select "Edit in DataSet designer."
  • Select the bottom entry, which should say "Fill, GetData()."
  • In the Properties window, click on the CommandText property. Right-click the ellipsis to the right to open the Query Builder.
  • Use the Query Builder to enter the new query.
  • Click OK. When it asks if you want to rebuild the commands, click Yes.
  • Close the DataSet designer. Click yes to save.

I'm not sure that will work but it's all I can think to try off hand.

Probably a better approach would be to add a view to the database to select the data that you want to display. Then you should be able to drag and drop the view onto the form.

You could also try using Entity Framework objects. I've only used them a little so I don't have any good information for you about them. Searching for information on using Entity Framework will probably get you better information than I can give you off hand.

One problem with any change of this kind is that the data adapter may be unable to figure out how to save changes to the database so you might end up with a read-only view.

Normally for "real" database applications, I don't use the drag and drop method. Instead I use my own DataAdapter and DataSet code to select, display, and update the data. It's more work but I have a better understanding of exactly what's happening.

For some examples that do something like that, see these examples:

Finally, if you need to a lot of this sort of thing, you should probably look for a good database programming book. The "24-Hour Trainer" book is really just to get you started and only covers database programming a little bit. It's a huge topic so you may want more in-depth information.

I hope that helps. Let me know if you find a good approach or if you're still stuck and I'll try to find a more concrete example for you.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)