Forum guidelines
AuthorQuestion
No mapping exists
Posted By Dan on 01 Apr 2008

I have a contact form submitting data to a sql 2005 table on a Win2003 server. The form takes the textbox data and saves it in session variables, then tries to insert these into the table. I can post the rest of the code if necessary. The stack and error are listed below. Am I getting this error because the data needs converted to an integer somewhere? Im clueless as to why this is coming up. If anyone can suggest something I would gladly appreciate the advice. Thank you in advance.

No mapping exists from object type System.Web.UI.WebControls.Label to a known managed provider native type.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: No mapping exists from object type System.Web.UI.WebControls.Label to a known managed provider native type.

Source Error:

 
Line 82:        
Line 83:             sqlCmd.Connection = sqlConn;
Line 84:             SqlDataReader sqlRdr = sqlCmd.ExecuteReader();
Line 85:         }
Line 86:         catch (SqlException ex)

Stack Trace:

 
[ArgumentException: No mapping exists from object type System.Web.UI.WebControls.Label to a known managed provider native type.]
   System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen) +1329
   System.Data.SqlClient.SqlParameter.GetMetaTypeOnly() +774328
   System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc) +14
   System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters) +166
   System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc) +253
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
   System.Data.SqlClient.SqlCommand.ExecuteReader() +84
   DollRegistration.VerifyItemRegistration(Object sender, EventArgs e) in d:\Inetpub\testroot\DollRegistration2.aspx.cs:84
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

AuthorReply
Re: No mapping exists
Posted By Scott Lysle on 02 Apr 2008  
It might have something to do with how you are setting up the parameters; I have seen this when someone defined the datatype using typeof(System.Whatever) (for example) instead of the SqlDbType.Whatever but you did not post any code here so I am not sure. 
slysle
Dan
  • 0
  • 0
Re: No mapping exists
Posted By Dan on 02 Apr 2008  

UPDATE:


After searching for an hour I found some helpful info on the asp.net forums. Turns out the reason this error showed up was I was trying to set the session variable equal to just the name of the label. So as an example I had this:

session["variable"] = lblName;

And it needed to be:

session["variable"] = lblName.Text;


Re: No mapping exists
Posted By Kevin Rollins on 10 Jun 2009  
FYI...I just received this in setting up SqlParameters when trying to cast a SqlInt as an int. Fix is to do this: new SqlParameter("@SeminarID", Convert.ToInt32(sem.SeminarID.Value)) Instead of this: new SqlParameter("@SeminarID", Convert.ToInt32(sem.SeminarID)

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.