Re: How to refresh a datatable?? by Alex
Alex
Tue May 03 15:05:09 CDT 2005
Hello Bill!
Thank you so much for your help and enthusiasm.
I think that all you said is very correct in the case the DataTable points
to a real Table. But in my case, the DataTable, in fact, is a VIEW (so as I
understand, It's a RUNTIME QUERY or VIRTUAL Table), it means that I can not
Insert/Delete/Modify any data in the VIEW directly, instead of it, i can
only Insert/Delete/Modify the data in the table IncomeProducts. In order to
display all the updated data in the DataGrid (DataGrid is used to display
the VIEW), I must execute the Query again (refresh VIEW again--->load all
data again), right???
Regards!
"W.G. Ryan eMVP" <WilliamRyan@gmail.com> wrote in message
news:#oovJ6AUFHA.3840@tk2msftngp13.phx.gbl...
> > 1. Want to ask you If I do correctly????
> From the looks of everything, it looks ok
>
> > 2. Now Everytime when i want to add a new 'row' to the table
> IncomeProducts,
>
> From the looks of how this is set up, you have two options. One is that
you
> can store the Datatable in session or viewstate, and each times someone
> makes an addition, add a datarow to the datatable with the new
information.
> When they are done with all of their editing, you can pass the datatable
to
> an adapter configured to handle the update. Or, each time you can call
> update. In most cases you'll probably want to opt for the latter.
Assuming
> that your update is successful, the database and the local datatable
should
> look the same with the exception of new rows added/deleted/modified by
other
> users. If this isn't a problem, then you don't need to requery the
database
> b/c the datatable and the database will match as soon as you fire the
> update. If you absolutely needed to have the data match and knew that you
> didn't want to overwrite any data that was changed by someone else, the
> safest way to do it is check for new data with a new select and
repopulate.
> There are a few ways to go about this but this is what you are trying to
> avoid right?
>
> Anway, by just submitting your updates your table and db will match as
long
> as no exceptions are raised so I think you're good to go.
>
> If I misunderstood what you were asking though or didn't answer your
> question to your satisfaction, please let me know.
>
> Cheers,
>
> Bill
>
> --
> W.G. Ryan, MVP
>
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "Alex" <chipheo2k@mail.ru> wrote in message
> news:eeSt7LAUFHA.612@TK2MSFTNGP12.phx.gbl...
> > Hello!
> > I have a small prob, so pls help me to solve it.
> > I have 2 tables
> > Products(ProductID, ProductName, Price)
> > Stores(StoreID, StoreName)
> > now I must design a table for Income-Product: IncomeProducts(id, Date ,
> > ProductID, Quantity, Price, Total, StoreID).
> > But I want to display the table IncomeProducts in the DataGrid like that
:
> > | ProductName | Price | Quantity | Total | StoreName
> > To do it: I use VIEW to make a visual Table (IncomeProductView):
> > SELECT dbo.IncomeProducts.[Date],
> > dbo.Products.ProductName,dbo.IncomeProducts.Price,
> > dbo.IncomeProducts.Quantity,
> dbo.IncomeProducts.Total,
> > dbo.Stores.StoreName
> > FROM dbo.IncomeProducts INNER JOIN
> > dbo.Products ON dbo.IncomeProducts.ProductID =
> > dbo.Products.ProductID INNER JOIN
> > dbo.Stores ON dbo.IncomeProducts.StoreID =
> > dbo.Stores.StoreID
> >
> >
> >
> >
> > And now I display this View on the DataGrid
> > ...
> > SqlDataAdapter sda..
> > DataSet ds
> > sda.Fill(ds, "IncomeProductView");
> > DataGrid dg;
> > dg.DataSource = ds.Tables["IncomeProductView"];
> > ....
> >
> > 1. Want to ask you If I do correctly????
>
> > I want it to be displayed in the DataGrid ( to do that, the View must
> > refresh to get the new inserted row). How can I do it???? or I must
Clear
> > the ds and "Download" again??? It's very bad......
> >
> >
> > Thanks
> >
> >
>
>