c# - ADO.NET database saves, but doesn't save -


i have program allows user fill out information, stored in local database. can execute stored procedure handles fine, when check data through visual studio changes aren't there. if run program , enter duplicate primary key, error thrown value exists. i've made sure there no duplicate files.

any suggestions?

stored procedure

create procedure [dbo].[newuser] @username text, @password text, @attackmethod text, @statpreference text     insert users     values (@username,@password,@attackmethod,@statpreference) return 0 

and code runs throw database.

            try         {             connection.open();             sqlcommand command = new sqlcommand("newuser",connection);             command.connection = connection;              command.commandtype = commandtype.storedprocedure;             command.parameters.addwithvalue("@username", sqldbtype.nvarchar);             command.parameters.addwithvalue("@password", sqldbtype.text);             command.parameters.addwithvalue("@attackmethod", sqldbtype.text);             command.parameters.addwithvalue("@statpreference", sqldbtype.text);             command.parameters["@username"].value = this.name;             command.parameters["@password"].value = this.password;             command.parameters["@attackmethod"].value = this.attackmethod;             command.parameters["@statpreference"].value = this.skillpreference;             command.executenonquery();             connection.close();             return true;         }         catch(exception ex)         {             system.windows.forms.messagebox.show(ex.message);              connection.close();             return false;         } 

addwithvalue method supposed take parametername , object representing value, not sqldbtype there problem there. @username not same @username. 1 has capital u.

try pattern instead:

command.parameters.add("@username ", sqldbtype.text); command.parameters["@username "].value = this.name; 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -