By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,704 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,704 IT Pros & Developers. It's quick & easy.

Dataset problem

P: n/a
I have the following problem:

I am populating a dataset but, sometimes (NOT always), the
NewRow method works like the Add method.

SetRightDetail.RightDetail.Rows.Clear()
For Each Right In TblRight.Rows
With Right
Detail = SetRightDetail.RightDetail.NewRow() (1)
Detail.Item("PKID") = .Item("PKID") (2)
Detail.Item("Type") = .Item("Type")
SetRightDetail.RightDetail.Rows.Add(Detail) (3)
End With
Next

Following is one example of the results after the lines
1,2,3 are executed:

Right.Item("PKID") Detail.Item("PKID")
NewRow Result

Iter 1:
(1) 1 DBNull
DBNull OK
(2) 1 1
DBNull OK
(3) 1 1
1 OK

Iter 2:
(1) 2 DBNull
DBNull OK
(2) 2 2
2 WRONG
(3) Generates an exception error for
duplicated primary key WRONG

What can I do to avoid the problem?

Thanks in advance,
LDV-ME
Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Cor
Hi Micky,

You can include a find (datarowcollection.find)

something as see it as pseudo
\\\\
dim detail as datarow = SetRightDetail.RightDetail.Rows.find(thekey)
if detail Is nothing then
Detail = SetRightDetail.RightDetail.NewRow()
detail.item(key) = key
SetRightDetail.RightDetail.Rows.Add(Detail)
end if
detail = ............................
////
I hope this helps

Cor

"Miky" <le******@davinci.com> schreef in bericht
news:08****************************@phx.gbl...
I have the following problem:

I am populating a dataset but, sometimes (NOT always), the
NewRow method works like the Add method.

SetRightDetail.RightDetail.Rows.Clear()
For Each Right In TblRight.Rows
With Right
Detail = SetRightDetail.RightDetail.NewRow() (1)
Detail.Item("PKID") = .Item("PKID") (2)
Detail.Item("Type") = .Item("Type")
SetRightDetail.RightDetail.Rows.Add(Detail) (3)
End With
Next

Following is one example of the results after the lines
1,2,3 are executed:

Right.Item("PKID") Detail.Item("PKID")
NewRow Result

Iter 1:
(1) 1 DBNull
DBNull OK
(2) 1 1
DBNull OK
(3) 1 1
1 OK

Iter 2:
(1) 2 DBNull
DBNull OK
(2) 2 2
2 WRONG
(3) Generates an exception error for
duplicated primary key WRONG

What can I do to avoid the problem?

Thanks in advance,
LDV-ME

Nov 20 '05 #2

P: n/a
Thanks for your answer.

The problem is that the datarow isn't physically on the
table (it has been cleared just before entering in the
for...next loop) and the source table contains only 1 row
(it has the same primary key).

It looks like that after Detail is set to the NewRow, it
will point always to the same memory address and
consequently they will change together.

I tried to bypass the Add for the second row and after
everything was OK. The second row (in the source table)
has never been added to the target table.

I tried to use the find getting back only the first row.

Thanks,
LDV-ME.
-----Original Message-----
Hi Micky,

You can include a find (datarowcollection.find)

something as see it as pseudo
\\\\
dim detail as datarow = SetRightDetail.RightDetail.Rows.find(thekey)if detail Is nothing then
Detail = SetRightDetail.RightDetail.NewRow()
detail.item(key) = key
SetRightDetail.RightDetail.Rows.Add(Detail)
end if
detail = ............................
////
I hope this helps

Cor

"Miky" <le******@davinci.com> schreef in bericht
news:08****************************@phx.gbl...
I have the following problem:

I am populating a dataset but, sometimes (NOT always), the NewRow method works like the Add method.

SetRightDetail.RightDetail.Rows.Clear()
For Each Right In TblRight.Rows
With Right
Detail = SetRightDetail.RightDetail.NewRow() (1)
Detail.Item("PKID") = .Item("PKID") (2)
Detail.Item("Type") = .Item("Type")
SetRightDetail.RightDetail.Rows.Add(Detail) (3)
End With
Next

Following is one example of the results after the lines
1,2,3 are executed:

Right.Item("PKID") Detail.Item("PKID")
NewRow Result

Iter 1:
(1) 1 DBNull
DBNull OK
(2) 1 1
DBNull OK
(3) 1 1
1 OK

Iter 2:
(1) 2 DBNull
DBNull OK
(2) 2 2
2 WRONG
(3) Generates an exception error for
duplicated primary key WRONG

What can I do to avoid the problem?

Thanks in advance,
LDV-ME

.

Nov 20 '05 #3

P: n/a
Just a correction to my previous post.

Using the find function I get the same problem.

One way I avoided the problem I put a try...catch when I
was adding the row to the dataset (getting back all the
rows)... but still I would like to understand why.

Thanks again,
LDV-ME.
-----Original Message-----
Thanks for your answer.

The problem is that the datarow isn't physically on the
table (it has been cleared just before entering in the
for...next loop) and the source table contains only 1 row
(it has the same primary key).

It looks like that after Detail is set to the NewRow, it
will point always to the same memory address and
consequently they will change together.

I tried to bypass the Add for the second row and after
everything was OK. The second row (in the source table)
has never been added to the target table.

I tried to use the find getting back only the first row.

Thanks,
LDV-ME.
-----Original Message-----
Hi Micky,

You can include a find (datarowcollection.find)

something as see it as pseudo
\\\\
dim detail as datarow =

SetRightDetail.RightDetail.Rows.find(thekey)
if detail Is nothing then
Detail = SetRightDetail.RightDetail.NewRow()
detail.item(key) = key
SetRightDetail.RightDetail.Rows.Add(Detail)
end if
detail = ............................
////
I hope this helps

Cor

"Miky" <le******@davinci.com> schreef in bericht
news:08****************************@phx.gbl...
I have the following problem:

I am populating a dataset but, sometimes (NOT always),the NewRow method works like the Add method.

SetRightDetail.RightDetail.Rows.Clear()
For Each Right In TblRight.Rows
With Right
Detail = SetRightDetail.RightDetail.NewRow() (1) Detail.Item("PKID") = .Item("PKID") (2)
Detail.Item("Type") = .Item("Type")
SetRightDetail.RightDetail.Rows.Add(Detail) (3)
End With
Next

Following is one example of the results after the lines
1,2,3 are executed:

Right.Item("PKID") Detail.Item("PKID")
NewRow Result

Iter 1:
(1) 1 DBNull
DBNull OK
(2) 1 1
DBNull OK
(3) 1 1
1 OK

Iter 2:
(1) 2 DBNull
DBNull OK
(2) 2 2
2 WRONG
(3) Generates an exception error for
duplicated primary key WRONG

What can I do to avoid the problem?

Thanks in advance,
LDV-ME

.

.

Nov 20 '05 #4

P: n/a
Hi Miky

Thanks for you posting in the group!

We will look into it and reply with more information here.
Please post here if you have any more concerns.
Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 20 '05 #5

P: n/a
Cor
Hi Micky,

When you use a
try
' something
catch
'nothing in it
end try

You never get a real error, that is real bad behaviour.

If you have only one row in one table from a dataset why not just do
ds1.tables(0).rows(0)("myfirstItem") = ds2.tables(0).rows(0)("myfirstItem")
ds1.tables(0).rows(0)("mySecondItem") =
ds2.tables(0).rows(0)("mySecondItem")

And if you are sure the key is only item(0) and the datasets schemas are
equal
for i as integer = 1 to ds1.tables(0).rowcount - 1
ds1.tables(0).rows(0)(i) = ds2.tables(0).rows(0)(i)
next
To do all items in one time.

All typed in this message so watch typos

I hope this helps,

Cor
Just a correction to my previous post.

Using the find function I get the same problem.

One way I avoided the problem I put a try...catch when I
was adding the row to the dataset (getting back all the
rows)... but still I would like to understand why.

Nov 20 '05 #6

P: n/a
Thanks again Cor,

I know it is bad but it was the only way I found to bypass the error.
Actually in the catch I call the sub itself and when returns back to the
parent sub I have the entire dataset in the correct way.

I don't have only one row but I could have between 2 and 100 rows and the
XML schemas are not equals (there are equals elements but in different
positions).

In the application I have other datasets and they work just fine. This is
the first time this problem happened to me, and even more strange, it
happens only the first time the application call the sub... after that, it
works fine.

Thanks again,
LDV-ME.

"Cor" <no*@non.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Hi Micky,

When you use a
try
' something
catch
'nothing in it
end try

You never get a real error, that is real bad behaviour.

If you have only one row in one table from a dataset why not just do
ds1.tables(0).rows(0)("myfirstItem") = ds2.tables(0).rows(0)("myfirstItem") ds1.tables(0).rows(0)("mySecondItem") =
ds2.tables(0).rows(0)("mySecondItem")

And if you are sure the key is only item(0) and the datasets schemas are
equal
for i as integer = 1 to ds1.tables(0).rowcount - 1
ds1.tables(0).rows(0)(i) = ds2.tables(0).rows(0)(i)
next
To do all items in one time.

All typed in this message so watch typos

I hope this helps,

Cor
Just a correction to my previous post.

Using the find function I get the same problem.

One way I avoided the problem I put a try...catch when I
was adding the row to the dataset (getting back all the
rows)... but still I would like to understand why.


Nov 20 '05 #7

P: n/a
Hi LDV-ME,

To find out whether or not there is another better method to resolve this
problem, would you please make a small sample to demonstrate how to
reproduce the same problem, so that I am able to reproduce the same problem
and perform further research on my side?

If you have further information about this problem, please let me know.
Best regards,

Kevin Sun
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #8

P: n/a
Thanks for your answer.

I tried to create a fast sample, but I cannot reproduce
the problem. As soon as I solve a more urgent problem that
it is stopping the deployment, I will work on reproducing
the problem.

Question: How can I post an attachment to my message from
the web interface, if I need to add files other than the
form to reproduce the error? I cannot use other programs
to access to the newsgroup.

Thanks,
LDV-ME
-----Original Message-----
Hi LDV-ME,

To find out whether or not there is another better method to resolve thisproblem, would you please make a small sample to demonstrate how toreproduce the same problem, so that I am able to reproduce the same problemand perform further research on my side?

If you have further information about this problem, please let me know.

Best regards,

Kevin Sun
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
.

Nov 20 '05 #9

P: n/a
Hi LDV-ME,

You are able to send files to me directly to zh****@microsoft.com. Note to
provide detailed reproducing steps. I cannot reach you by email
le******@davinci.com.
If you have further information about this problem, please let me know.
Best regards,

Kevin Sun
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.