Solved

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

Posted on 2011-03-02
3
1,522 Views
Last Modified: 2012-06-27
Hi ! I wrote following code in aspx file

<asp:Panel ID="Panel1" runat="server">
                    <h2>
                            Add New Mantle Image</h2>
                        <label>
                            Image Path</label>
                        <p>
                        <asp:TextBox ID="file" runat="server" />
                            <!--<input type="file" runat="server" id="File1"/> -->
                            <asp:Literal ID="lblmessage" runat="server"/>
                            </p>
                         <label>URL (optional)</label>
                        <p>
                        <asp:TextBox ID="url1" runat="server" />
                   <!--   <input type="text" runat="server" id="url" /> -->
                        </p>
                        <p>
                            <label>
                            Title of Image (optional)</label><input type="text"
                            runat="server" id="title" /></p>
                       <asp:CheckBox ID="Position" runat="server" Text="Top in the order?" Font-Bold="true" TextAlign="Left" />
                        <br />
                        <br />
                        <asp:CheckBox ID="CheckBox1" runat="server" Text="Published?  " Font-Bold="True"
                            TextAlign="Left" />
                        <div class="clear spacer">
                        </div>
                       
                      </asp:Panel>
                      <p align="center">
                        <asp:ImageButton ID="savebutton" runat="server" ImageUrl="assets/images/button_save.gif" OnClick="SaveButton_click" />
                            <input type="image" src="assets/images/button_cancel.gif" class="submit inline" onclick="history.go(-1);return false;" />
                        </p>


And following code in aspx.cs file:
                 try
                 {
                      m_db.OpenCommand();
                        m_db.Command.CommandText = "insert into mantle(title, url, image, position, published, deleted) values(@ttl, @img,@pos,@url, @publish,@del)";
                        m_db.Command.Parameters.AddWithValue("@ttl", title);
                        m_db.Command.Parameters.AddWithValue("@url", url);
                        m_db.Command.Parameters.AddWithValue("@img", image);
                        m_db.Command.Parameters.AddWithValue("@pos", position);
                        m_db.Command.Parameters.AddWithValue("@publish", CheckBox1.Checked ? "1" : "0");
                        m_db.Command.Parameters.AddWithValue("@del", "0");

                        m_db.DBExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                        errorfree = false;
                    }


And I am getting this error while debugging:

System.ArgumentException was caught
  Message=No mapping exists from object type System.Web.UI.HtmlControls.HtmlInputText to a known managed provider native type.
  Source=System.Data
  StackTrace:
       at System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen)
       at System.Data.SqlClient.SqlParameter.GetMetaTypeOnly()
       at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
       at System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters)
       at System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at NeboWeb.Utilities.Data.database.DBExecuteNonQuery() in c:\inetpub\wwwroot\App_Code\database.cs:line 81
       at CMS_MantleAdd.SaveButton_Event() in c:\inetpub\wwwroot\CMS\MantleAdd.aspx.cs:line 94
  InnerException:
0
Comment
Question by:pratz09
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35016593
You appear to be trying to pass the control itself to your command, rather than it's value. Should be more like:
m_db.Command.Parameters.AddWithValue("@ttl", title[b].Text[/b]);

Open in new window

0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35016598
Ok, bold obviously doesn't work in code snippets :)
m_db.Command.Parameters.AddWithValue("@ttl", title.Text); 

Open in new window

0
 

Author Comment

by:pratz09
ID: 35017479
Oh Man.. Can't believe it was so silly mistake. Thanks man.


0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question