all groups > dotnet windows forms databinding > september 2006 >
You're in the

dotnet windows forms databinding

group:

How to do batch-update from DataGrid?


How to do batch-update from DataGrid? Duong Nguyen
9/23/2006 12:00:00 AM
dotnet windows forms databinding:
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.


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

Re: How to do batch-update from DataGrid? Bart Mermuys
9/23/2006 11:18:42 AM
Hi,

[quoted text, click to 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


[quoted text, click to view]

Re: How to do batch-update from DataGrid? Bart Mermuys
9/23/2006 8:49:09 PM
Hi,

[quoted text, click to view]

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

[quoted text, click to view]

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


[quoted text, click to view]

Re: How to do batch-update from DataGrid? Duong Nguyen
9/23/2006 10:59:33 PM
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?



--
Contact:
Bauman Moscow State Technical University
Russia, Moscow 105005
Tel: +7915-426-6272
ICQ: 160-223-078
YM: Chipheo2k
[quoted text, click to view]

AddThis Social Bookmark Button