473,750 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Jun 27 '08 #1
5 4079
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.

--
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
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
Jun 27 '08 #2
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
"Holger Kreissl" <di*******@gmai l.comwrote in message
news:0D******** *************** ***********@mic rosoft.com...
>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.

--
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
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

Jun 27 '08 #3
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

--
Holger Kreissl
..NET Software Developer
http://kreissl.blogspot.com/
Jun 27 '08 #4
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...
Jun 27 '08 #5
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
"Patrice" <http://www.chez.com/scribe/wrote in message
news:OJ******** ******@TK2MSFTN GP04.phx.gbl...
>
>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...


Jun 27 '08 #6

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

Similar topics

3
6416
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName, Employees.LastName, TerritoryID, Employees.EmployeeID, RegionID, ProductID from Employees
1
9757
by: db55 | last post by:
I have some users that I need to run stored procedures, but they can't seem to run them unless they are in the db_owner role of the database. How do I give them access to run the stored procs without giving them the complete rights of the db_owner role? Thanks in advance.
6
3102
by: Dave | last post by:
1) I know that we can define an external proc to be Fenced or NotFenced on "CREATE PROCEDURE" command. I don't see the FENCED / NOT FENCED option on "Create Procedure" for SQL stored procs. Is it always "NotFenced" for SQL stored procs by any chance ? We are in the process of migrating a SQL server app to DB2 with 2000 stored procs and the DB2 server keeps crashing too often during stored procs execution. 2) I have read somewhere...
0
1102
by: mimo | last post by:
Hi, Is there like a sample application in ASP.NET 2.0 somewhere that uses stored procs to pull, insert, update, and delete data?
2
1623
by: gkellymail | last post by:
the following query works fine: select link.idx, link.x_table, link.x_id_a, link.x_id_z, a.strandid, b.strandid from link_detail, link, strand A, strand B where link_detail.x_table = 'enclosure' and link_detail.x_id = 3 and link.idx = link_detail.linkidx and A.strandid = link.x_id_a and B.strandid = link.x_id_z would someone please convert this to a more efficient query using inner
1
1715
by: kentk | last post by:
Is there a difference in how SQL Server 7 and SQL 2000 processes SQL passed from a program by an ADO command object. Reason I ask is I rewrote a couple applications a couple years ago were the SQL statements were inline. I basically took the SQL statements and put them into stored procs, were there were variables in the code I used SQL parameters in the stored procs. I got some amazing performance results by switching to stored procs. ...
15
2282
by: Burt | last post by:
I'm a stored proc guy, but a lot of people at my company use inline sql in their apps, sometimes putting the sql in a text file, sometimes hardcoding it. They don't see much benefit from procs, and say anyway they're are db specific- what if we change from SQL Server to Oracle one day? What say you experts? Is this one of those "no right answer" questions? Thanks,
2
1784
by: Andy B | last post by:
Is there an easy way to convert tableAdaptor queries into stored procs without messing up the dataTables in the dataSet or losing the queries themselves?
8
2632
by: Frank Calahan | last post by:
I've been looking at LINQ and it seems very nice to be able to make queries in code, but I use stored procs for efficiency. If LINQ to SQL only works with SQL Server and stored procs are more efficient, what use is LINQ to SQL, other than to have a simpler way to call my stored proc?
0
9001
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8838
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9396
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6808
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.