c# - No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type -


this code

sqlcommand cmd = new sqlcommand("spregisteruser", con); cmd.commandtype = commandtype.storedprocedure;  sqlparameter username = new sqlparameter("@username", txtusername.text);  sqlparameter password = new sqlparameter("@password", txtpassword); sqlparameter email = new sqlparameter("@email", txtemail.text); sqlparameter usertype = new sqlparameter("@usertype", sqldbtype.nvarchar, 200); usertype.value = "student"; cmd.parameters.add(username); cmd.parameters.add(password); cmd.parameters.add(email); cmd.parameters.add(usertype);  con.open();  int returncode = (int)cmd.executescalar(); //this displays error message if (returncode == -1) 

any ideas?

here error message

 no mapping exists object type system.web.ui.webcontrols.textbox known managed provider native type. 

description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.

exception details: system.argumentexception: no mapping exists object type system.web.ui.webcontrols.textbox known managed provider native type.  source error:   line 48:                     con.open(); line 49:  line 50:                     int returncode = (int)cmd.executescalar(); line 51:                     if (returncode == -1) line 52:                     {       source file: c:\users\mubashir\documents\visual studio 2012\projects\sit302groupproject\sit302groupproject\registration\registration.aspx.cs    line: 50      stack trace:       [argumentexception: no mapping exists object type system.web.ui.webcontrols.textbox known managed provider native type.]        system.data.sqlclient.metatype.getmetatypefromvalue(type datatype, object value, boolean inferlen, boolean streamallowed) +2021139        system.data.sqlclient.sqlparameter.getmetatypeonly() +5287377        system.data.sqlclient.sqlparameter.validate(int32 index, boolean iscommandproc) +16        system.data.sqlclient.sqlcommand.setuprpcparameters(_sqlrpc rpc, int32 startcount, boolean inschema, sqlparametercollection parameters) +122        system.data.sqlclient.sqlcommand.buildrpc(boolean inschema, sqlparametercollection parameters, _sqlrpc& rpc) +78        system.data.sqlclient.sqlcommand.runexecutereadertds(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, boolean async, int32 timeout, task& task, boolean asyncwrite) +1379        system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method, taskcompletionsource`1 completion, int32 timeout, task& task, boolean asyncwrite) +175        system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method) +53        system.data.sqlclient.sqlcommand.executescalar() +149        sit302groupproject.registration.btnregister_click(object sender, eventargs e) in c:\users\mubashir\documents\visual studio 2012\projects\sit302groupproject\sit302groupproject\registration\registration.aspx.cs:50        system.web.ui.webcontrols.button.onclick(eventargs e) +9552602        system.web.ui.webcontrols.button.raisepostbackevent(string eventargument) +103        system.web.ui.webcontrols.button.system.web.ui.ipostbackeventhandler.raisepostbackevent(string eventargument) +10        system.web.ui.page.raisepostbackevent(ipostbackeventhandler sourcecontrol, string eventargument) +13        system.web.ui.page.raisepostbackevent(namevaluecollection postdata) +35        system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) +1724 

here stored procedure

    create proc spregisteruser @username nvarchar(100), @password nvarchar(200), @email  nvarchar(200), @usertype  nvarchar(200),  begin  declare @count int declare @returncode int  select @count = count(username) tblusers username = @username if @count > 0 begin  set @return = -1 end else begin set @returncode = 1 insert tblusers values (@username, @password, @email, @usertype) end select @returncode returnvalue end 

you passing txtpassword object of textbox, getting exception.

problem in line

sqlparameter password = new sqlparameter("@password", txtpassword); 

so change code to

sqlparameter password = new sqlparameter("@password", txtpassword.text); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -