473,405 Members | 2,272 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,405 software developers and data experts.

Can you update through a view?

I am using VS2005 and have been learning a ton about databinding. I know
that when you drag a view from the datasource window (creating a
dataGridView) that an update method is not added to the table adaptor. I
would like to update the b ase tables thorugh the view. How do i do this?

FYI: I have some reserarch on how to handle updating multiple tables and
making sure I don't break referential integrity, yet in this case I will not
be adding or deleteing, only updating. From what I've read I understand that
I should create temperary datatables to store the add, mod, and del changes
and then update them in the correct order (Child delete, Parent Insert,
Parent Mod, Child Insert, Child Mod, grandChild insert, GrandChild Mod).

I currenlty have the sql stored on teh server as a view, should I be storing
the sql in the application? In that case wouldn't have a bound table
adaptor? I guess Im a little fuzzy on creating bound table adaptors whose
result set is not in the format of an exisitng table? I thought I had to
creat a view? Sorta babbling now.... hope this makes sence.

Thanks,
Greg P.
May 8 '06 #1
6 5187
Hi Grep,

The UpdateCommand is not created for the DataSource, because it is selected
from a view. To create the DeleteCommand and UpdateCommand, there is a
prerequisite. The source must have a primary key for the update command to
detect which row in the table to update. Since it is a View, we cannot
generate the update command for it.

If you really want to update the datasource with the data in a
DataGridView, it think dragging and dropping from the DataSource windows is
not suitable here. Because it only satisfies the most basic usage. If you
want to use drag and drop, you have to make the DataSource a table instead
of a View in SQL database. Or you have to create the typed DataSet and
create the DataAdapter with your own code to do the updates.

HTH.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 10 '06 #2
Kevin,

1) I understand that Microsoft can't generate the updateCommand but can I
add it afterwards? This would allow me to use some functionality from the
drag and drop and add what I need. I do have the pirmary key of the table
that I want to update included in the view. I just hide the column in the
dataGridView.

2) If the answer to this is no, then I want to confirm what you are saying.
I can use the existing dataSet but I need to create my own TableAdaptor and
not use the generated TableAdaptor? If so how do I add the UpdateCommand?
Same question as #1, if microsoft creates it or if I do how do I add a new
Command. (I will look into some reference material as soon as I'm done
writting this)

3) Finally is it easier to use ADO.NET and recordSet (or the .net
equivelant) to do this? I could execute stored procedures to do this based
on dataGridView.cellValueChanged?

Thanks again, you have been great.

Greg P.

"Kevin Yu [MSFT]" wrote:
Hi Grep,

The UpdateCommand is not created for the DataSource, because it is selected
from a view. To create the DeleteCommand and UpdateCommand, there is a
prerequisite. The source must have a primary key for the update command to
detect which row in the table to update. Since it is a View, we cannot
generate the update command for it.

If you really want to update the datasource with the data in a
DataGridView, it think dragging and dropping from the DataSource windows is
not suitable here. Because it only satisfies the most basic usage. If you
want to use drag and drop, you have to make the DataSource a table instead
of a View in SQL database. Or you have to create the typed DataSet and
create the DataAdapter with your own code to do the updates.

HTH.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 10 '06 #3
After 2 Bass Ales and the doulble episode of House I got an update working.
(by the way House was awsome!) This works with a Drag and Drop from the
DataSource window. I added a tableAdaptor to my exisiting typed DataSet
(DataSource).xsd file. I used the "use existing stored procedures" to create
a select, insert, update and delete methods for a drag and drop dataGridView.
Is there any other way to do this besides using stored procedures? I will
use them if I need to but that is a lot of stored procedures for all of the
data acccess in my application. Yet this is much cleaner than hand coding
the ADO myself. I'm pretty happy right now... time for Bass Ale #3 while I
begin writing 4 stored procedures for every view I will be using in my app...
:-)

Greg P.

"Greg P" wrote:
Kevin,

1) I understand that Microsoft can't generate the updateCommand but can I
add it afterwards? This would allow me to use some functionality from the
drag and drop and add what I need. I do have the pirmary key of the table
that I want to update included in the view. I just hide the column in the
dataGridView.

2) If the answer to this is no, then I want to confirm what you are saying.
I can use the existing dataSet but I need to create my own TableAdaptor and
not use the generated TableAdaptor? If so how do I add the UpdateCommand?
Same question as #1, if microsoft creates it or if I do how do I add a new
Command. (I will look into some reference material as soon as I'm done
writting this)

3) Finally is it easier to use ADO.NET and recordSet (or the .net
equivelant) to do this? I could execute stored procedures to do this based
on dataGridView.cellValueChanged?

Thanks again, you have been great.

Greg P.

"Kevin Yu [MSFT]" wrote:
Hi Grep,

The UpdateCommand is not created for the DataSource, because it is selected
from a view. To create the DeleteCommand and UpdateCommand, there is a
prerequisite. The source must have a primary key for the update command to
detect which row in the table to update. Since it is a View, we cannot
generate the update command for it.

If you really want to update the datasource with the data in a
DataGridView, it think dragging and dropping from the DataSource windows is
not suitable here. Because it only satisfies the most basic usage. If you
want to use drag and drop, you have to make the DataSource a table instead
of a View in SQL database. Or you have to create the typed DataSet and
create the DataAdapter with your own code to do the updates.

HTH.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 10 '06 #4
Hi Greg,

Yes, using existing stored procedure can customize the updating procedure.
Also, if you double click on the DataSet designer, it will generate another
file for you to add additional code for the typed DataSet. But in my
opinion, using the existing SP will be more elegant.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 10 '06 #5
Thanks Kevin!

"Kevin Yu [MSFT]" wrote:
Hi Greg,

Yes, using existing stored procedure can customize the updating procedure.
Also, if you double click on the DataSet designer, it will generate another
file for you to add additional code for the typed DataSet. But in my
opinion, using the existing SP will be more elegant.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 10 '06 #6
You're welcome!

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 11 '06 #7

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

Similar topics

3
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does...
4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
2
by: fig000 | last post by:
Hi, I have an application that's running fine on development servers (web and database-sql server 2000). I'm updating a record through a third party component but I don't think the component...
6
by: Eugene | last post by:
Summary: ---------- Updates against UNION ALL view does't do branch elimination, but rather reads all the branches (partitions). The case scenario(DB2 V8.1.4a ESE, AIX 5.2):...
3
by: Megan | last post by:
hi everybody- it seems like my update query should work. the sql view seems logical. but that might be up to discussion...lol...i'm a newbie! UPDATE , Issue SET .IssueID = . WHERE ((.=.));
3
by: | last post by:
Hi, I have a major problem. I use Windows 2000 highest SP and ACCESS 2000 inside Office 2000 SP-3. I want to use the following simple command inside ACCESS in VBA UPDATE tbl_SATURN_Benutzer...
3
by: V T | last post by:
Hello all, SQL Server 2000 documentation http://www.microsoft.com/technet/prodtechnol/sql/2000/reskit/part10/c3761.mspx states that if view is using "NOT NULL" columns of a base table, then...
2
by: L.Peter | last post by:
Hi Group, I have a gridview bound to a sqldatasource, this datasource pulls data out from select and update procedures with 10 update parameters the gridview has 15 columns, in edit mode, I want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.