Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

TableAdapter, INNER JOINs, stored procs, and problems with Update

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bogdan - 16 Apr 2008 16:10 GMT
Hi,

I have a stored procedure that uses JOINs to return columns from multiple
tables.  I also have another stored proc that that takes a series of params
and updates multiple tables.  I used the framework to auto-generate a table
adapter specifying both stored procs as Get/Fill and Update.  The problem is
that columns from the JOINed table seem to marked as 'read-only' so trying
to update a row results in an exception.  BTW, by default a FormView
attached (indirectly through ODS and BLL) to the table adapter did not show
Edit/Insert/Delete buttons. I had to switch its default mode to Edit.

I remember reading about JOINs and TableAdapters and that they do not work
well together.  I'm not sure though is this was also applicable to stored
procedures.  It was suggested that subqueries be used instead.  The problem
is that subqueries are good if used with one field per JOINed table.  In my
case, I need to join 3 tables and each of them has about 5 columns.

So, my questions is:
Can table adapters be used with stored procedures that take columns from
multiple tables for update purposes?  If yes, could someone please let me
know how to do that?  If not, what are the alternatives?

I would really, really appreciate _any_ suggestions.

My example of select and update procs:

SELECT a.c1, a.c2, a.c3,
          b.c1, b.c2, bc3,
          c.c1, c.c2, c.c3,
          d.c1, d.c2, d.c3
FROM A a
INNER JOIN B b ON a.c1= b.c1
LEFT OUTER JOIN C c ON a.c1 = c.c1
LEFT OUTER JOIN D d ON a.c1 = d.c1
WHERE a.c1 = @c1;

[...]

-- Update
@ac2 int,
@ac3 int,
@bc2 int,
@bc3 int,
@cc2 int,
[...]

UPDATE A
   SET c2 = @ac2 [...]
UPDATE B
   SET c2 = @bc2 [...]

etc.

Thanks,
Bogdan
Holger Kreissl - 17 Apr 2008 10:23 GMT
I believe its not possible. The way to go is to design a dataset including
the relations you need... So you can make your view over the datatables and
the update will work because the typed dataset knows about the relations
between the tables.

Signature

Holger Kreissl
.NET Software Developer
http://kreissl.blogspot.com/

> I have a stored procedure that uses JOINs to return columns from multiple
> tables.  I also have another stored proc that that takes a series of
[quoted text clipped - 51 lines]
> Thanks,
> Bogdan
Bogdan - 17 Apr 2008 13:17 GMT
Holger,

Thanks for your reply.

When you mentioned 'design dataset [...] make your view over the datatables'
did you mean database level or application level (i.e. asp.net datasets,
etc.)?

I'm just curious why updates of JOINed tables are not allowed/recommended
for stored procs.  It seems like this is about passing correct params to the
procedure which in turn takes care of updating the relevant tables.

I did experiment with table adapter's tables by setting the Readonly
attribute to false of the 'problematic' columns before updating them.  It
seemed to work but I'm not sure if I'm asking for trouble by doing this.

I might post another question specific to the Readonly attribute and see if
anyone can help.

Thanks,
Bogdan

>I believe its not possible. The way to go is to design a dataset including
>the relations you need... So you can make your view over the datatables and
[quoted text clipped - 56 lines]
>> Thanks,
>> Bogdan
Holger Kreissl - 17 Apr 2008 13:35 GMT
> When you mentioned 'design dataset [...] make your view over the
> datatables' did you mean database level or application level (i.e. asp.net
> datasets, etc.)?

yes i mean the application level. When you create a Dataset with multiple
Tables and their relations you are able to update the whole dataset with all
its relation tables and data...

I will follow this. Maybe there are better ways like you hope too ;)

Greetings

Signature

Holger Kreissl
.NET Software Developer
http://kreissl.blogspot.com/

Patrice - 17 Apr 2008 13:56 GMT
> I'm just curious why updates of JOINed tables are not allowed/recommended
> for stored procs.  It seems like this is about passing correct params to
> the procedure which in turn takes care of updating the relevant tables.

This is general for joins. For example what if you update a column in the
outer join part. There is no actual record to update. If you delete a line
which line in which underlying table are you supposed to delete ? etc...
etc...
Bogdan - 17 Apr 2008 14:43 GMT
Patrice,

Thanks for the reply.  I absolutely agree with your point but _only_ when
dealing with ad-hoc sql queries.  The stored proc case is different - at
least from a non-asp.net guy.  The stored proc that I'd like to use for
updates takes care of the concerns that you have raised.  If framework
auto-generated code (i.e. table adapter, etc.) could simply treat my stored
proc as a 'black box' that can be trusted when it comes to updates and
simply pass the required parameters then I'd be very happy.  But, I guess,
there is more to it that I'm aware of at the moment.

Thanks,
Bogdan

>> I'm just curious why updates of JOINed tables are not allowed/recommended
>> for stored procs.  It seems like this is about passing correct params to
[quoted text clipped - 4 lines]
> which line in which underlying table are you supposed to delete ? etc...
> etc...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.