A couple of questions about updating data through a dataset
- From: "Rod" <rodf@xxxxxxxxxxxxxxxxx>
- Date: Wed, 15 Jun 2005 14:55:22 -0600
I have been using .NET for three years. We are currently using VS .NET 2003
and SQL Server 2000. Whenever I have needed to update data I normally
created a SqlCommand object, assigned it the appropriate string (depending
upon whether it is a stored procedure or not) and executed it. However, now
I would like to use the SqlDataAdapter's UpdateCommand and Update() method.
However, I am running into problems, which I think I can break down into two
questions. The first is, how do I assign values to the dataset which I want
to be updated? For example, if I have something like this:
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?
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
.
- Follow-Ups:
- Re: A couple of questions about updating data through a dataset
- From: W.G. Ryan eMVP
- Re: A couple of questions about updating data through a dataset
- Prev by Date: RE: row display in a datagrid
- Next by Date: Re: DataGrid - clever way to update DataSet
- Previous by thread: Re: DB Independence
- Next by thread: Re: A couple of questions about updating data through a dataset
- Index(es):
Relevant Pages
|