473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Adding information to a dataset...

I have the following code in a Sub which is called by a do loop statement for
each line starting with unit info in an e-mail based game that I play. I'm
exctracting the keywords from the text and then trying to add them to a
dataset that draw's it's columnnames from an empty access database table (the
primary key of the database is UnitNo):

Dim drw1 As DataRow = dasUnitInfo.Tables("UnitInfo").NewRow()
drw1("UnitNumber") = UnitNo
drw1("UnitName") = UnitName
drw1("FactionNumber") = FactionNo
dasUnitInfo.Tables("UnitInfo").Rows.Add(drw1)

Now what happens is strange. the 1st time it hits the drw1 statement it has
the value of 1244 as the unitnumber. it seems to add the row fine (I can't
tell what info it adds as it's in th middle of the code). the next time it
hits the drw1 statement it's using 1741 as the unitnumber, however when it
tries to add the row it errors out with the message:

Colum UnitNumber is constrained to be unique. Value 1741 is already present.

Because it's in a try/catch statement it carries on and imports the
remaining rows fine. However the 1st unitnumber row isn't in the dataset.
now the only way I've found to get round this issue is by using the following
command just before the loop statement starts:

drwx("UnitNumber") = 123456
dasUnitInfo.Tables("UnitInfo").Rows.Add(drwx)

if I put the "dasUnitInfo.Tables("UnitInfo").Rows.Add(drwx) " command to
the end of the above then it does the same error but with the 1st unitnumber
not the second.

it seems like it need some sort of info in the promary key field before
it'll consider adding the rows correctly. Is there a reason for this? is
there a better way to make it work without this fix above as I feel it's not
a very neat way to fix the problem?

Any advice would be appreciated

Niels

Nov 21 '05 #1
2 1479
Mistake in the earlier code:

drwx("UnitNumber") = 123456
dasUnitInfo.Tables("UnitInfo").Rows.Add(drwx)

should have read:

Dim drwx As DataRow = dasUnitInfo.Tables("UnitInfo").NewRow()
drwx("UnitNumber") = 123456

Niels

"Niels Jensen" wrote:
I have the following code in a Sub which is called by a do loop statement for
each line starting with unit info in an e-mail based game that I play. I'm
exctracting the keywords from the text and then trying to add them to a
dataset that draw's it's columnnames from an empty access database table (the
primary key of the database is UnitNo):

Dim drw1 As DataRow = dasUnitInfo.Tables("UnitInfo").NewRow()
drw1("UnitNumber") = UnitNo
drw1("UnitName") = UnitName
drw1("FactionNumber") = FactionNo
dasUnitInfo.Tables("UnitInfo").Rows.Add(drw1)

Now what happens is strange. the 1st time it hits the drw1 statement it has
the value of 1244 as the unitnumber. it seems to add the row fine (I can't
tell what info it adds as it's in th middle of the code). the next time it
hits the drw1 statement it's using 1741 as the unitnumber, however when it
tries to add the row it errors out with the message:

Colum UnitNumber is constrained to be unique. Value 1741 is already present.

Because it's in a try/catch statement it carries on and imports the
remaining rows fine. However the 1st unitnumber row isn't in the dataset.
now the only way I've found to get round this issue is by using the following
command just before the loop statement starts:

drwx("UnitNumber") = 123456
dasUnitInfo.Tables("UnitInfo").Rows.Add(drwx)

if I put the "dasUnitInfo.Tables("UnitInfo").Rows.Add(drwx) " command to
the end of the above then it does the same error but with the 1st unitnumber
not the second.

it seems like it need some sort of info in the promary key field before
it'll consider adding the rows correctly. Is there a reason for this? is
there a better way to make it work without this fix above as I feel it's not
a very neat way to fix the problem?

Any advice would be appreciated

Niels


Nov 21 '05 #2
I've found another way round it too?!?

When the program launches the datatable is active and has the focus. there
is a flashing cursor in the unitnumber field which has a value of (null). now
if I click on a different datatable then it imports fine - the error only
happens if the datatable that holds the unitinfo is selected. Why would this
happen, and why wouldn't it have the same effect on the information being
imported to the alternate datatable? the information in the second datatable
also had a primary key and the table structure is pulled from a blank access
table

I'm confused! :-o

Niels

"Niels Jensen" wrote:
Mistake in the earlier code:

drwx("UnitNumber") = 123456
dasUnitInfo.Tables("UnitInfo").Rows.Add(drwx)

should have read:

Dim drwx As DataRow = dasUnitInfo.Tables("UnitInfo").NewRow()
drwx("UnitNumber") = 123456

Niels

"Niels Jensen" wrote:
I have the following code in a Sub which is called by a do loop statement for
each line starting with unit info in an e-mail based game that I play. I'm
exctracting the keywords from the text and then trying to add them to a
dataset that draw's it's columnnames from an empty access database table (the
primary key of the database is UnitNo):

Dim drw1 As DataRow = dasUnitInfo.Tables("UnitInfo").NewRow()
drw1("UnitNumber") = UnitNo
drw1("UnitName") = UnitName
drw1("FactionNumber") = FactionNo
dasUnitInfo.Tables("UnitInfo").Rows.Add(drw1)

Now what happens is strange. the 1st time it hits the drw1 statement it has
the value of 1244 as the unitnumber. it seems to add the row fine (I can't
tell what info it adds as it's in th middle of the code). the next time it
hits the drw1 statement it's using 1741 as the unitnumber, however when it
tries to add the row it errors out with the message:

Colum UnitNumber is constrained to be unique. Value 1741 is already present.

Because it's in a try/catch statement it carries on and imports the
remaining rows fine. However the 1st unitnumber row isn't in the dataset.
now the only way I've found to get round this issue is by using the following
command just before the loop statement starts:

drwx("UnitNumber") = 123456
dasUnitInfo.Tables("UnitInfo").Rows.Add(drwx)

if I put the "dasUnitInfo.Tables("UnitInfo").Rows.Add(drwx) " command to
the end of the above then it does the same error but with the 1st unitnumber
not the second.

it seems like it need some sort of info in the promary key field before
it'll consider adding the rows correctly. Is there a reason for this? is
there a better way to make it work without this fix above as I feel it's not
a very neat way to fix the problem?

Any advice would be appreciated

Niels


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
4
by: Will Pittenger | last post by:
I have a project where the backend is Access. I have learned (slowly) to use OLEDB to access my data. However, to save changes, I need to generate a SQL statement. This seems clunky. I am used...
2
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
4
by: paul | last post by:
Hi, Im trying to add a dataset to the app_code directory using vs2005 \ SQL2005 beta 2. When I run through the wizard I select the option to auto create new Stored Procedures (Select, update,...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
12
by: cjobes | last post by:
Hi all, I'm trying to create a dataset as a component to make it accessable from all forms. I have used that following code so far in the component designer: Inherits...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.