472,811 Members | 1,625 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 3997
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*******@gmail.comwrote in message
news:0D**********************************@microsof t.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**************@TK2MSFTNGP04.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
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,...
1
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...
6
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...
0
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
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 =...
1
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...
15
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...
2
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
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.