As
SystemserialNo is the primary key of your table
ConfigurationDetails and you're letting the user enter the value for it (in textBox1) it's really trivial: You entered a primary key which already existed in that table.
If you entered it a second time because there actually is a second item/part that has the same
SystemserialNo then your choice of
SystemserialNo as the primary key isn't right.
If there can't be a second item/part with the same
SystemserialNo then you need to check that first before attempting to insert what the user entered and if it already exists, notify the user without inserting it into the database.
Apart from that:
- Don't use string-concatenation for SQL-statements. Your code becomes susceptible to SQL-injection and less readable/maintainable. Use
SQL-parameters[
^] instead.
- Give your controls (textBox1 - 3 here) meaningful names (all designer generated identifiers in general). That's easy with the F2-refactoring of Visual Studio.
- Validate user input before relying on its validity (unless you've just not shown it here, the TextBox-inputs could be empty or otherwise invalid).
- Use
using
-statements with your Sql*****-objects in order to safely free the allocated system resources.