Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am working on my shop project in visual basic 2017 and SQL server express 2014

the same error consist in inserting a data to log information tabel

data tabel as


Id (pk,int not null)
user_name (nvarchar,50)
password (nvarchar,50)
login_time(datetime 7 null)
login_date(datetime 7 null)

and my code is
i am not going to insert a pk value in this query ,

please need help

What I have tried:

sql.AddParam("@u1", m_name)
    sql.AddParam("@u2", TxtPAssword.Text)
    sql.AddParam("@u3", m_time)
    sql.AddParam("@u4", dt1)
    sql.ExecQuery("Insert into user_log(user_name,password,login_time,login_date) " &
                  "Values(@u1,@u2,@u3,@u4)")
    If Noerrors(True) = False Then MsgBox(sql.Exception)
Posted
Updated 23-Feb-18 10:50am

1 solution

You haven't set the IDENTITY property on the Id column. As a result, every time you insert without specifying a value, it's trying to use the default value, which you've set to 0.

The Id column is the primary key. You can't have more than one record in the table with the same primary key. Therefore, your insert fails with the error in your question.

Either specify the Id in your INSERT query, or set the IDENTITY property on that column.

IDENTITY (Property) (Transact-SQL) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900