I created a DataGrid and bound a DataView of a typed DataSet to it (i tried
with the DataSet as well but i'd rather use the DataView as i'm using it for
sorting). I have paging working, sorting and the edit template is cool. When
i hit Update i wonder what i have to do to update the database with the user
inputted values.

Now in a perfect world the datagrid, bound to my view would have a method
for updating the selected row of the dataset/view with the templated values.
All i had to do is call myDataAdapter.Update(myDataSet) to make the changes
in the database. I've been looking for this and i can't seem to find a way
to do it though.

I found a lot of examples using a string or stored procedure to update the
values through a new Command object, but i was wondering why i shouldn't use
the automaticly generated update, delete, insert of my typed dataset? To
find the row i want to update i'd do something like this
myTypedDataRow = myTable.Rows.FindById(selectedId);

Now my biggest problem is how do i find the selectedId of the row just
edited? I already set the Key on the datagrid, so it knows the key of my
datatable, yet all the fancy methods on my DataGridEventArgs (or what it's
called - i don't have VS/my project here) all just return the index in the
datagrid - so since the Id is not the same as the index in the datagrid i
can't use it.

Anyone know how to solve this or have a good tutorial on DataGrids? I
searched for a good one, but only found very simple examples that didn't
cover my problem :(

Thanks!
Per

Re: updating a typed dataset (newbie question?) by Kathleen

Kathleen
Fri Jul 11 11:49:19 CDT 2003

Per,

I assumed you were Windows.Forms because ASP.NET data binding is inherently
one way.

You have to work out your own updating strategy.

Kathleen


"Per Hornshøj-Schierbeck" <nospam@microsoft.com> wrote in message
news:#ucTpKxRDHA.212@TK2MSFTNGP10.phx.gbl...
> Hi Kathleen!
>
> Thanks for the relpy - i'll try and comment :) Perhaps i forgot to mention
> that this is an ASP.NET project, actually i only do ASP.NET so that's why
i
> forgot to mention it's not a winforms project. Perhaps that's why it's not
> working?
>
> > Your datagrid is updating your DataSet, or should be. Don't have any
> > AcceptChanges between the Fill and Update (actually don't have any
unless
> > you are really certain you understand why you need them)
>
> Yep, if i call AcceptChanges the RowStatus will change and they won't get
> updated when i call .Update()
>
> > Your typed DataSet does not have Insert, Deleted, Upate, etc. commands,
> > assumign you are usng the Microsoft typed dataset generator and have not
> > extended it.
>
> When i check the design-generated code all the commands are there - so
they
> should be there? I also checked when i created the dataset.
>
> > > Now in a perfect world the datagrid, bound to my view would have a
> method
> > > for updating the selected row of the dataset/view with the templated
> > values.
> > > All i had to do is call myDataAdapter.Update(myDataSet) to make the
> > changes
> > > in the database. I've been looking for this and i can't seem to find a
> way
> > > to do it though.
> >
> > That is all you have to do. Do you have your DataAdapter, and DataSet
> > available?
>
> Ok great! How come there are no examples of this automaticly update? Hold
on
> a second - i'm using ASP.NET and not winforms - is there a difference
there?
>
>
> > > Now my biggest problem is how do i find the selectedId of the row just
> > > edited? I already set the Key on the datagrid, so it knows the key of
my
> > > datatable, yet all the fancy methods on my DataGridEventArgs (or what
> it's
> > > called - i don't have VS/my project here) all just return the index in
> the
> > > datagrid - so since the Id is not the same as the index in the
datagrid
> i
> > > can't use it.
> >
> > I am not clear why you need it. The currency manager associated with
your
> > DataGrid has a Current method.
>
> How do i access that? Perhaps i forgot to tell it's an <asp:DataGrid>
> control i'm using for asp.net and not winforms - is that only available
for
> winforms?
>
> > > Now my biggest problem is how do i find the selectedId of the row just
> > > edited? I already set the Key on the datagrid, so it knows the key of
my
> > > datatable, yet all the fancy methods on my DataGridEventArgs (or what
> it's
> > > called - i don't have VS/my project here) all just return the index in
> the
> > > datagrid - so since the Id is not the same as the index in the
datagrid
> i
> > > can't use it.
>
> I figured this part out, even though i shouldn't need this if i get the
> automaticly update to work.
> The trick was using either
> myDataSet.myTypedTable.Rows[e.Item.ItemIndex];
> or access the .DataKeys[e.Item.ItemIndex] to get the key value ;)
>
> Per
>
>



Re: updating a typed dataset (newbie question?) by Per

Per
Mon Jul 14 02:47:03 CDT 2003


"Kathleen Dollard" <kathleen@mvps.org> wrote in message
news:%23z83cx8RDHA.2480@tk2msftngp13.phx.gbl...
> Per,
>
> I assumed you were Windows.Forms because ASP.NET data binding is
inherently
> one way.
>
> You have to work out your own updating strategy.
>
> Kathleen

Nod thanks :) I found a way (actually two different ones i posted earlier)
to do it so it's cool. I just wanted to make sure i wasn't doing it the hard
way (if there was an easier one).