Link to home
Create AccountLog in
Avatar of J. Ross Hughson
J. Ross HughsonFlag for Canada

asked on

Why am I getting a duplicate key value error when it isn't?

First, let me say that I'm very new to programming and especially working with MS SQL Server. Here's my problem:
The code in the attached file works well when creating a new row with new data. I then forced an error to test my "Catch" statement and it worked as well. My problem is that I then changed one of the text boxes from which the key value is created but I'm still getting the duplicate key value error. I used MessageBox to show that it was changing the key value so I don't understand what's happening. Do I need to initialize the Data Adapter or Data Table before I run this each time? Please keep any explanations simple enough for a newbie to understand.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Without knowing more about your table setup it's hard to say, but you need to find out the actual error you're getting instead of returning your own. Try this in the Catch handler:

Catch dbException As System.Data.SqlClient.SqlException
            boolCreateBinderOK = False
            MessageBox.Show("SQLException: " & dbException.ToString)

Catch ex As Exception
            boolCreateBinderOK = False
            MessageBox.Show("Exception: " & ex.ToString)

Run it and report back what the issue is.
Avatar of J. Ross Hughson
J. Ross Hughson
Flag of Canada image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
You really should Delete this question, since no solution was provided. I'm objecting, which will allow you to Delete the question instead of accepting a non-solution as the answer.
Avatar of J. Ross Hughson


There were no solutions offered that dealt with the problem.