Re: A couple of questions about updating data through a dataset



Thank you, W.G. for replying. My reply is in-line (towards the bottom):


"W.G. Ryan eMVP" <WilliamRyan@xxxxxxxxx> wrote in message
news:uPGOixfcFHA.720@xxxxxxxxxxxxxxxxxxxxxxx
>> DataRow r = DataTable.Rows[0];
>>
>> and the row has a column named FirstName, can I do this:
>>
>> r["FirstName"] = "Rod";
>>
>> or do I have to do something like this first:
>>
>> r.BeginEdit();
>> r["FirstName"] = "Rod";
>>
>> And if I do have to use the BeginEdit() method, do I also have to issue
>> the EndEdit() method? Or will that basically clear the row's Current
>> view and reassign that to the Original view?
>
> If you are doing this programatically, then no you don't. THe problme is
> that when you use the UI, often it will start the beginedit but nothing
> triggers the end edit. HOwever, I'd highly recommed that you do use
> beginedit. If you don't, then for instance, if your values are sorted, it
> could affect the sort immediately.
>
>>
>> I know that the datarow's SourceVersion will come into play, but I am not
>> sure how.
>>
>> Second question: What DOES the Update() method of the SqlDataAdapter
>> really work on? For example, after struggling with this for half the day
>> I finally got rid of the error message I was getting saying,
>>
>> "Procedure 'spMyProc' expects parameter '@FirstName', which was not
>> supplied"
>>
>> to go away, but now when I assign a value to the datarow's FirstName
>> column, then I would have expected that to actually be saved to the
>> database when I issued the SqlDataAdapter's Update() method. Instead, it
>> just quietly goes about its business and nothing at all is saved/updated.
>> So, what I am doing wrong now?
>>
>> Rod
>
> Update goes through each row and looks at the RowState. If it's modified,
> added, deleted, then it looks to the corresponding command and fires it.
> If you look at the overload for a dataColumn DataColumn dc = new
> DataColumn("ColumnName", typeof(Whatever), Column). This is the value
> that will map back to the parameter if you've coded your CRUD correctly or
> of you had it generated. IF you don't have any changeds, you can call
> Update all year and nothing will happen. If you call Update and you have
> modified rows but no update command, you'll get an exception. It maps
> those values back to the params.
>
> Does this answer your question?

Almost. I will modify a column in the dataset, but then when I call the
Update() method of the SqlDataAdapter it doesn't save/change anything. I
don't understand how I could modify the value but then the Update() not
work.

BTW, I am doing this programmatically, rather than using any wizard like the
CommandBuilder.

> BTW< I'd highly encourage using a Keyed table, and using the DataAdapter
> Configuration wizard and deconstructing what it created. You'll learn a
> lot - or at least, I did.
>
> --
> W.G. Ryan, MVP
>


.



Relevant Pages

  • Re: How do I unlock a file ? / SOLVED !
    ... BTW one more question: ... MythTV is a directory! ... Isn't "rmdir" the command to remove a directory ??? ...
    (Ubuntu)
  • Re: Cannot open multiple IE windows!!
    ... I have tapped all of the ideas I can readily call to my command on this one ... you are welcome BTW. ... How to make a good newsgroup post: ... > manny ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: [PATCH 03/13] scsi: unify allocation of scsi command and sense buffer
    ... command and simplifying the code. ... two slabs to start with but can't find any reason. ... Btw, we might just want to declare the sense buffer directly as a sized ... command allocation to the LLDD. ...
    (Linux-Kernel)
  • Re: empty bodies in outlook 6.0
    ... I had noted the space in the command line. ... I hope the CWShreder will help... ... Already made a AV scan and Spyware scan btw... ... > This problem began in March and this has been the fix for all but one ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Please Help
    ... Yep, from what I've seen, the Configuration wizard just uses the command ... Greg Low ... > HTH, ...
    (microsoft.public.dotnet.framework.adonet)