Update Row DataSet

  • Thread starter Thread starter samoore
  • Start date Start date
S

samoore

I have found two or three places where it states that to update an item
in a dataset, all I have to do is do
DataSet.Tables[0].Rows[0].ItemArray[1] = "String". When I attempt to do
this it does not work.

Any help would be appreciated.
 
Hi,

You can set the entire ItemArray property to a new object[], but setting any
one element will not update the DataRow.
 
Dave

Is a little bit cryptic today

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]
{........................};

Cor
 
Cor

I do that, or at least I think I do that. I have put my code below to
show what I am doing.

switch(spReturn.Trim())
{
case "PROBLEM: CSONO NOT IN RB":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Contact
Customer Service";
break;
case "Being Picked":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
case "Can Cancel":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Item Can
Not Be Cancelled";
break;
case "TRACKING NUMBER":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
}

When I check the DataSet to see if there are any changes or if the
rowstate has chaned, neither have changed. I am apparently missing
something, just not sure what???

Scott Moore

Dave

Is a little bit cryptic today

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]
{........................};

Cor

samoore said:
I have found two or three places where it states that to update an item
in a dataset, all I have to do is do
DataSet.Tables[0].Rows[0].ItemArray[1] = "String". When I attempt to do
this it does not work.

Any help would be appreciated.
 
Hi,

Take a look at Cor's examples again:

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]

Now, take a look at one of yours:
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Contact
Customer Service";

Do you see the difference?

Cor's first example is indexing into the rows to get the row at index zero.
Then, it's indexing into that row's columns to get the column at index 1 and
is assigning the value to that column. In his second example, he's setting
the entire ItemArray property to a new object array (almost. It should be
something like: new object[] { "col 1", "col 2" }).

In your example, you're indexing into the object[] returned by the ItemArray
property and setting element 12 to be "Contact Customer Service". Since
ItemArray is returning a copy of the items in the DataRow, your code is just
updating the copy. You should be doing one of the following instead:

ReturnValue.Tables[0].Rows[count][12] = "col 12 value";
or
ReturnValue.Tables[0].Rows[count].ItemArray =
new object[] { col1, col2, col3... "col 12 value", ...};

Obviously, the first approach is much simpler in your case ;)

--
Dave Sexton

samoore said:
Cor

I do that, or at least I think I do that. I have put my code below to
show what I am doing.

switch(spReturn.Trim())
{
case "PROBLEM: CSONO NOT IN RB":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Contact
Customer Service";
break;
case "Being Picked":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
case "Can Cancel":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Item Can
Not Be Cancelled";
break;
case "TRACKING NUMBER":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
}

When I check the DataSet to see if there are any changes or if the
rowstate has chaned, neither have changed. I am apparently missing
something, just not sure what???

Scott Moore

Dave

Is a little bit cryptic today

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]
{........................};

Cor

samoore said:
I have found two or three places where it states that to update an item
in a dataset, all I have to do is do
DataSet.Tables[0].Rows[0].ItemArray[1] = "String". When I attempt to do
this it does not work.

Any help would be appreciated.
 
All Hail Cor and David. Thanks once again for the help. Appreciate it.

Scott Moore

Dave said:
Hi,

Take a look at Cor's examples again:

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]

Now, take a look at one of yours:
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Contact
Customer Service";

Do you see the difference?

Cor's first example is indexing into the rows to get the row at index zero.
Then, it's indexing into that row's columns to get the column at index 1 and
is assigning the value to that column. In his second example, he's setting
the entire ItemArray property to a new object array (almost. It should be
something like: new object[] { "col 1", "col 2" }).

In your example, you're indexing into the object[] returned by the ItemArray
property and setting element 12 to be "Contact Customer Service". Since
ItemArray is returning a copy of the items in the DataRow, your code is just
updating the copy. You should be doing one of the following instead:

ReturnValue.Tables[0].Rows[count][12] = "col 12 value";
or
ReturnValue.Tables[0].Rows[count].ItemArray =
new object[] { col1, col2, col3... "col 12 value", ...};

Obviously, the first approach is much simpler in your case ;)

--
Dave Sexton

samoore said:
Cor

I do that, or at least I think I do that. I have put my code below to
show what I am doing.

switch(spReturn.Trim())
{
case "PROBLEM: CSONO NOT IN RB":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Contact
Customer Service";
break;
case "Being Picked":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
case "Can Cancel":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Item Can
Not Be Cancelled";
break;
case "TRACKING NUMBER":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
}

When I check the DataSet to see if there are any changes or if the
rowstate has chaned, neither have changed. I am apparently missing
something, just not sure what???

Scott Moore

Dave

Is a little bit cryptic today

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]
{........................};

Cor

"samoore" <[email protected]> schreef in bericht
I have found two or three places where it states that to update an item
in a dataset, all I have to do is do
DataSet.Tables[0].Rows[0].ItemArray[1] = "String". When I attempt to do
this it does not work.

Any help would be appreciated.
 
Dave,

Probably you did not see my {......................} it had a carriage
return, however never mind, nice done by you.

Cor

Dave Sexton said:
Hi,

Take a look at Cor's examples again:

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]

Now, take a look at one of yours:
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Contact
Customer Service";

Do you see the difference?

Cor's first example is indexing into the rows to get the row at index
zero. Then, it's indexing into that row's columns to get the column at
index 1 and is assigning the value to that column. In his second example,
he's setting the entire ItemArray property to a new object array (almost.
It should be something like: new object[] { "col 1", "col 2" }).

In your example, you're indexing into the object[] returned by the
ItemArray property and setting element 12 to be "Contact Customer
Service". Since ItemArray is returning a copy of the items in the
DataRow, your code is just updating the copy. You should be doing one of
the following instead:

ReturnValue.Tables[0].Rows[count][12] = "col 12 value";
or
ReturnValue.Tables[0].Rows[count].ItemArray =
new object[] { col1, col2, col3... "col 12 value", ...};

Obviously, the first approach is much simpler in your case ;)

--
Dave Sexton

samoore said:
Cor

I do that, or at least I think I do that. I have put my code below to
show what I am doing.

switch(spReturn.Trim())
{
case "PROBLEM: CSONO NOT IN RB":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Contact
Customer Service";
break;
case "Being Picked":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
case "Can Cancel":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Item Can
Not Be Cancelled";
break;
case "TRACKING NUMBER":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
}

When I check the DataSet to see if there are any changes or if the
rowstate has chaned, neither have changed. I am apparently missing
something, just not sure what???

Scott Moore

Dave

Is a little bit cryptic today

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]
{........................};

Cor

"samoore" <[email protected]> schreef in bericht
I have found two or three places where it states that to update an item
in a dataset, all I have to do is do
DataSet.Tables[0].Rows[0].ItemArray[1] = "String". When I attempt to
do
this it does not work.

Any help would be appreciated.
 
Hi Cor,

Yes, I missed that ;)

--
Dave Sexton

Cor Ligthert said:
Dave,

Probably you did not see my {......................} it had a carriage
return, however never mind, nice done by you.

Cor

Dave Sexton said:
Hi,

Take a look at Cor's examples again:

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]

Now, take a look at one of yours:
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Contact
Customer Service";

Do you see the difference?

Cor's first example is indexing into the rows to get the row at index
zero. Then, it's indexing into that row's columns to get the column at
index 1 and is assigning the value to that column. In his second
example, he's setting the entire ItemArray property to a new object array
(almost. It should be something like: new object[] { "col 1", "col 2" }).

In your example, you're indexing into the object[] returned by the
ItemArray property and setting element 12 to be "Contact Customer
Service". Since ItemArray is returning a copy of the items in the
DataRow, your code is just updating the copy. You should be doing one of
the following instead:

ReturnValue.Tables[0].Rows[count][12] = "col 12 value";
or
ReturnValue.Tables[0].Rows[count].ItemArray =
new object[] { col1, col2, col3... "col 12 value", ...};

Obviously, the first approach is much simpler in your case ;)

--
Dave Sexton

samoore said:
Cor

I do that, or at least I think I do that. I have put my code below to
show what I am doing.

switch(spReturn.Trim())
{
case "PROBLEM: CSONO NOT IN RB":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Contact
Customer Service";
break;
case "Being Picked":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
case "Can Cancel":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Item Can
Not Be Cancelled";
break;
case "TRACKING NUMBER":
ReturnValue.Tables[0].Rows[count].ItemArray[12] = "Being
Picked";
break;
}

When I check the DataSet to see if there are any changes or if the
rowstate has chaned, neither have changed. I am apparently missing
something, just not sure what???

Scott Moore


Cor Ligthert [MVP] wrote:
Dave

Is a little bit cryptic today

DataSet.Tables[0].Rows[0][1] = "String";
or
DataSet.Tables[0].Rows[0].ItemArray = new Object[]
{........................};

Cor

"samoore" <[email protected]> schreef in bericht
I have found two or three places where it states that to update an
item
in a dataset, all I have to do is do
DataSet.Tables[0].Rows[0].ItemArray[1] = "String". When I attempt to
do
this it does not work.

Any help would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top