c# - Violation of PRIMARY KEY constraint 'PK__tblmembe__DD7012648BA5EC8B' When insert in DataBase *** ASP.Net Query -


i create page insert users .

but when run the page show me error

error pic

asp code

protected void page_load(object sender, eventargs e) {     system.data.sqlclient.sqlconnection con = new system.data.sqlclient.sqlconnection();     con.connectionstring = system.configuration.configurationmanager.connectionstrings["shopdbconnectionstring"].connectionstring;     system.data.sqlclient.sqlcommand cmd = new system.data.sqlclient.sqlcommand();     cmd.commandtext = "insert tblmember values ('" + txtemail.text + "','" + txtname.text + "','" + txtfamily.text + "','" + txtpass.text + "','','" + dropdownlist1.selectedvalue + "') ";     cmd.commandtype = system.data.commandtype.text;     cmd.connection = con;     con.open();     cmd.executenonquery();     con.close();     response.redirect("default.aspx"); } 

my database

it seems you're not passing primary key in query, duplicate key shown empty (). email column uid (name confusing me) must unique. can't have 2 rows same primary key.

secondly , more important, not concatenate strings input build query. can injected harmful queries might drop database.

check example on how use parameterized queries.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -