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

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

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

c++ - Qt: Resize QScrollArea to show 4 widgets at most -