473,320 Members | 1,829 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,320 software developers and data experts.

vb.net SQL client violation of primary key?

5
i using vb.net and and insert into sql client, there is 3 column in a table, which r id, password and level, n just an empty table, when i do this
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2.  
  3.     Public Shared Sub xxx(ByVal sT As SecurityTier)
  4.  
  5.         Try
  6.             Dim id As String = sT.getID   'textbox value
  7.             Dim pass As String = sT.getPass   'textbox value
  8.             Dim ans As String = sT.getAns   'textbox value
  9.             Dim ra As Integer
  10.  
  11.             sqlcommand = "INSERT INTO Staff (Staff_ID, Staff_Pass, Staff_Level) "_ &
  12.                          "VALUES ('" & id & "','" & pass & "','" & ans & "')"
  13.             Initialize()
  14.             cmdBook = New SqlCommand(sqlcommand, conBook)
  15.             ra = cmdBook.ExecuteNonQuery
  16.  
  17.         Catch ex As SqlException
  18.             MessageBox.Show(ex.Message)
  19.         Finally
  20.             Terminate()
  21.         End Try
  22.  
  23.     End Sub
i get "violation of primary key constraint PK_Staff" although there is no data inside, how come?i

i remove the primary key in table just to test, but there is no data being insert, any help or guide will greatly appreciate
Feb 11 '09 #1
2 3613
Plater
7,872 Expert 4TB
Is Staff_ID set to be an Indentity? (auto-increment)
If so, then you shouldn't be trying to explicitly set it yourself.
Feb 11 '09 #2
Se0ng
5
no auto increment, just normal database, and by the way, i figure out something, c like i store in a "temporary" database, i can insert the data trough the \bin folder, but cannot insert when i run it in designer mode, by the way, whenever i run designer mode, the "temporary data" in \bin will gone, i not sure whats the problem, any help?or whether my sql connection have problem?but if have problem, then i suppose cannot select any data from database
Feb 12 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Edward | last post by:
Access 97 SR 2 Front End SQL Server 7.00.1063 Back End When I attempt to relink the tables in my Access app. I am suddenly getting this weird error message = "ODBC--Call Failed", followed by...
6
by: J Smith | last post by:
After doing some googling through the lists and such, I wasn't able to arrive at a solution for a problem I've run into recently. I've seen mention of similar symptoms, but my case seems different....
2
by: John | last post by:
The ASP application inserts transaction records in transaction table with the system time as the primary key. However, it is possible to have primary key violation because the records in...
2
by: mivey4 | last post by:
Okay I have 2 tables: Table A - holds a list of new hardware serial numbers and their corresponding model (no constraints or indexes) Table B - holds a distinct list of current serial numbers...
2
by: embarkr | last post by:
I am getting the error: "Violation of PRIMARY KEY constraint 'PK_tblCustomsTariffTreeMap'. Cannot insert duplicate key in object 'dbo.tblCustomsTariffCodeTreeMap'." However, the record I am...
1
by: Zamdrist | last post by:
Violation of PRIMARY KEY constraint 'PK_CUSTOM2'. Cannot insert duplicate key in object 'MHGROUP.Custom2' Is there ANY other reason this violation of the primary key would happen OTHER than a...
1
by: Walter Thizo | last post by:
Morning Programmers I have given project where there is corrupt database in the form of text file , what they need is paradox Boland c++ database that will handle the duplicates of student no...
2
by: rorajoey | last post by:
Violation of UNIQUE KEY constraint 'IX_surveyQuestions'. Cannot insert duplicate key in object 'dbo.surveyQuestions'. This might seem like a simple matter of trying to insert a row with ID=20 when...
1
by: crichard1983 | last post by:
I'm using a Unique Key constraint for the first time, and I think I may not be understanding something correctly. I have a table with a Primary key (media_format_id) that is auto-increment. Then I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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....

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.