473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Updating db from relational view - laborious or what?

Scenario:
I select data from a SQL Server View which links 3 tables, into a
single dataset table. I update some of those fields on a web form.
When I want to update the db, clearly I can't update via a View -
makes perfect sense.

But because I used a View, I can't use the CommandBuilder. I have to
specify my own Commands which will in some cases be huge and complex.
This seems crazy - what if I change the db structure? And because I
used a view, I've got no Primary Keys on my tables so I can't do
things like: DataRow myDataRow1 =
myDataSet.Tables["Customers"].Rows.Find("ALFKI");

It would clearly be simpler if I selected single tables using a Stored
Proc or a Select statement and then built the relationships manually,
but again, that sucks - what if I make changes to the db structure?
The same goes for the DataRow example above: I can specify on the
DataAdapter which column is the Primary Key but I don't want to be
coding db table metadata into my app.

Clearly, selecting and updating relational data is obviously a common
requirement, but ADO.NET makes the whole process incredibly laborious
and painful. And it ties the code directly to the structure of the db
which just has to be wrong.

Or I'm missing something. How are you guys handling the problem?
Nov 17 '05 #1
3 1292
Without knowing more about your database design, and the nature of the view,
it's hard to say much. Some views can be updatable.

When you say "I've got no Primary Keys on my tables", that's a little
worrying.

I tend to have a DataAccess class which works with SQL stored procedures,
and returns DataSets to it's callers. In some cases I'll have a class which
takes that DataSet, and exposes it in a more UI-friendly way by defining
properties to provide access to the records and fields of the DataSet.

At some level, your app will need to have some awareness of the database
structure. If only to access the data values by their column names in the
DataSet. If you were to change your underlying data structure, you could
still return a DataSet with the previous naming scheme. One way to make
this more explicit, is to avoid "select * ..." style queries. Always define
the fields that you want to be returned explicitly. That way, if you add
some columns to a table, any existing queries will be unaffected.

If you expect to change your database structure so drastically that the
relationships between your tables will be different, you ought to expect to
have to modify at least one aspect of the code that uses it.
Nov 17 '05 #2
William, I think we mostly agree. When I say "I've got no PKs on my
tables" I mean that, although the tables do have PKs (of course), when
they're returned to a DS via a View, it seems that ADO.Net can't
figure out which are the PK columns. So I have to define them myself
in the DS. Which is ridiculous.

As far as the CommandBuilder commands to update the DB are concerned,
as far as I understand it, I need to define the name, type, size etc
of every column I want to update. So it's not a question of only major
updates to the DB breaking the app, any minor - and let's face it,
pretty common - updates such as changing the length of the field will
do it as well.

Actually, I think I'm struggling toward understanding something a lot
more fundamental - it may be easier, from the point of view of
relationally updating a DB, to select individual tables and then
rebuild the relationships using a DataRelation (see
http://www.microsoft.com/mspress/boo...chap/5354i.asp - final para
in answer to the 2nd question).

My point in all of this is that the DAL is going to be tightly bound
to the DB. Even small changes will break the app. What happened to
abstraction and encapsulation? And what happened to RAD? This is all
SO laborious!
Nov 17 '05 #3
I've since found this article, which confirms my suspicions -
CommandBuilder sucks, Official.

http://msdn.microsoft.com/library/de...andbuilder.asp

I've never seen this sort of info anywhere else. Why on earth don't MS
just tell us that it can't handle Relational Views, Joins etc. Ok,
stupid question ...

I also found this, which was very helpful in understanding the
concepts. And I've ordered the book!

http://www.microsoft.com/mspress/boo...pchap/5354.asp

Hope this helps other poor sods trying to come to terms with this
mangled mess.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. ...
18
by: comcast | last post by:
Hello all, I am developing an interface system for an application I was written. This interface will connect to other system to share information. I would like to use xml and xsl to generically...
0
by: Olivier Jullian | last post by:
Hi, I'm new to .NET and am trying to take advantage of the object structure while accessing relational databases. I started a small project for managing "projects". Here is a description of...
7
by: Foxster | last post by:
in access i have two tables (tblplayer, tblpoints) in tblplayer i have field totalpoint (number) in tlbpoints i have field pointgame (number) the two files are related via idplayer now i made a...
1
by: Tim Fierro | last post by:
Hello, I have had many years using flat file databases (File Express from way back) but am now at a company where a relational database is needed and would carry us into the future. Since I...
6
by: Mike Wilson | last post by:
Dear Group, I have a heirarchical set of database tables, say - "order" and "order_type" and want to display a series of orders in a grid control, and in place of the order_type foreign key...
7
by: Pradeep | last post by:
Hello, I need to take a set of input tables and create an XML output file. The format of the XML output must be user-definable and must be intuitive enough for non-techies to use. input...
15
by: slinky | last post by:
Thanks in advance fo rany help... I have an XML data file (well- formed) that I need to place into my website's app_data folder. I would like to have an .aspx form on my site that simply has two...
24
by: sonos | last post by:
Hi, I am working on a program to archive data to disk. At what point is it best to use a relational database like MySQL as the backend instead of a C program alone? Thanks to any and all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.