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

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -