October 3, 2003 at 11:04 am
I am writing to a db through a windows form. I am pulling data from a ListView and looping through to write them. Many of the fields have the same data in them. Once the first record is written I get an error that tells me the row already belongs to the table.
I have worked around it by opening and closing the db connection within the loop, however it takes a very very very long time to complete.
Any suggestions on how to get around this. The records are not the same so I am unsure why I get the error. I have been told by others that it is a SQL bug.
Any help or suggestions would be great.
Thanks
Brent
October 3, 2003 at 11:21 am
Before inserting the next record try to check in the table if it already exists,if it exists then don't insert otherwise insert the record.
October 5, 2003 at 1:13 pm
Are you sure that the data in the loop is refreshing properly?
If after the 1st insert you get a violation it sounds like the data is the same..
Good luck
AJ Ahrens
Good Hunting!
AJ Ahrens
webmaster@kritter.net
October 6, 2003 at 3:15 am
hi!
what do you mean by "the data is the same"? are you using a primary key? if not, i'd strongly suggest you think about creating a pk. if the problem persists, you should think of how values for the pk/uk is provided and maybe introduce some of the process into your application respectively (normally the better solution) to the database itself (eg. identity columns, uniqueidentifiers, anything like that).
best regards,
chris.
October 6, 2003 at 3:49 am
Hi Brent,
quote:
I am writing to a db through a windows form. I am pulling data from a ListView and looping through to write them. Many of the fields have the same data in them. Once the first record is written I get an error that tells me the row already belongs to the table.I have worked around it by opening and closing the db connection within the loop, however it takes a very very very long time to complete.
Any suggestions on how to get around this. The records are not the same so I am unsure why I get the error. I have been told by others that it is a SQL bug.
it would surely help if you could post DDL of your table and maybe some snippets of the application code you use. Otherwise it only a shot in the dark
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
October 8, 2003 at 9:10 am
Hello everyone!
One suggestion could be to dump your records into and ADO recordset and do a BatchUpdate to a temporary table, insert the non-violating records into your Main table and return the rest to your App so it can elaborate them...
Regards, Hans!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply