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 / Windows Forms / WinForm Data Binding / September 2006

Tip: Looking for answers? Try searching our database.

How to do batch-update from DataGrid?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Duong Nguyen - 23 Sep 2006 10:15 GMT
Hello!
I have 2 tables: Products (ProductID, ProductName) and Inventory(ProductID,
Qty). I must display table Inventory in DataGrid (like in Excel) in order to
user can working with it (input Qty for each Product). In order to the sheet
look more friendly, I make o view Inventory_View( ProductID, ProductName,
Qty). Now bind this view to the datagrid

dg.DataSource = ds;
dg.DataMember = "Inventory_View";
...
Now, user can enter Qty for every product on datagrid. After that, when user
clicks on button Save, I must update the table Inventory. Pls help me to do
this update.
Thanks.

Signature

Contact:
Bauman Moscow State Technical University
Russia, Moscow 105005
Tel: +7915-426-6272
ICQ: 160-223-078
YM: Chipheo2k

Bart Mermuys - 23 Sep 2006 12:18 GMT
Hi,

> Hello!
> I have 2 tables: Products (ProductID, ProductName) and
[quoted text clipped - 6 lines]
> dg.DataSource = ds;
> dg.DataMember = "Inventory_View";

Some options:

1)
Don't load a view, instead load the Product table and Inventory table, add
the right relation and add an expression column, eg:

DataSet ds = ...contains loaded Inventory and Product table...;
ds.Relations.Add("relProdInv",
   ds.Tables["Product"].Columns["ID"] /*PK*/,
   ds.Tables["Inventory"].Columns["ProductID"] /*FK*/ );

ds.Tables["Inventory"].Columns.Add("ProductName", typeof(string),
"Parent(relProdInv).ProductName");

Then display the Inventory table, it will also show the ProductName, you
only need to update the Inventory table then.  Note that in NET1.1 it's
possible the update (DataAdapter.Update) will fail if there are expression
columns, so you need to remove them before and re-add them afterwards, bit
annoying but it works.

2)
Use your Inventory_View and setup an appropriate UpdateCommand on the
Inventory_View DataAdapter which should only include fields from the
Inventory Table.  If you have no idea how to do this, then use the designer
to setup an DataAdapter for the Inventory Table and have a look at the
designer generated code for the UpdateCommand.

If you have any problems, please mention what framework you're using 1.1 or
2.0 ?

HTH,
Greetings

> ...
> Now, user can enter Qty for every product on datagrid. After that, when
> user clicks on button Save, I must update the table Inventory. Pls help me
> to do this update.
> Thanks.
Duong Nguyen - 23 Sep 2006 20:03 GMT
Hi,
thanks for your help!
I want to ask you if I use typed DataSet, so I can add the relation by the
visual designer, but how can I add the expression column? Do I need add it
programmatically?

Signature

Contact:
Bauman Moscow State Technical University
Russia, Moscow 105005
Tel: +7915-426-6272
ICQ: 160-223-078
YM: Chipheo2k

> Hi,
>
[quoted text clipped - 47 lines]
>> me to do this update.
>> Thanks.
Bart Mermuys - 23 Sep 2006 21:49 GMT
Hi,

> Hi,
> thanks for your help!
> I want to ask you if I use typed DataSet, so I can add the relation by the
> visual designer,

Just to be clear, Products must be the parent and Inventory the child.

> but how can I add the expression column?

You still didn't mentioned if you're using NET1.1 or NET2.0, but i think
it's pretty much the same:  select your table inside the visual designer,
then click on the empty row and start typing to add a column, then open
"Property Window" and set the expression.

HTH,
Greetings

> Do I need add it programmatically?
>
[quoted text clipped - 49 lines]
>>> me to do this update.
>>> Thanks.

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.