Hi,
[quoted text, click to view] "Duong Nguyen" <Duongnguyen@mail.ru> wrote in message
news:%23DSkgAv3GHA.508@TK2MSFTNGP06.phx.gbl...
> 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";
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] > ...
> 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
>