C# 我只是在开发.net代码?

C# 我只是在开发.net代码?,c#,C#,错误: 对象类型System.Web.UI.WebControl.TextBox中不存在映射 到已知的托管提供程序本机类型 说明: 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源 异常详细信息:System.ArgumentException:不存在从对象类型System.Web.UI.WebControl.TextBox到已知托管提供程序本机类型的映射 源错误: code: using System; using System.

错误:

  • 对象类型System.Web.UI.WebControl.TextBox中不存在映射 到已知的托管提供程序本机类型
说明:

描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.ArgumentException:不存在从对象类型System.Web.UI.WebControl.TextBox到已知托管提供程序本机类型的映射

源错误:

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class Registration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
            conn.Open();
            String checkuser = "select count(*) from [UserData] where 'UserName'='"+ TextBox1UN.Text +"'";
            SqlCommand comm = new SqlCommand(checkuser,conn);
             int temp = Convert.ToInt32(comm.ExecuteScalar().ToString());
            if(temp==1)
            {
                Response.Write("user allready exists");

            }

         conn.Close();

        }

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
            {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
            conn.Open();
            String InserQuery = "insert into [UserData](UserName,Email,Password,Country)values(@Uname,@email,@pass,@country)";
            SqlCommand comm = new SqlCommand(InserQuery,conn);
            comm.Parameters.AddWithValue("@Uname", TextBox1UN.Text);
            comm.Parameters.AddWithValue("@email", TextBox2EI);
            comm.Parameters.AddWithValue("@pass", TextBox3PW.Text);
            comm.Parameters.AddWithValue("@country", DropDownList1cont.SelectedItem.ToString());
            comm.ExecuteNonQuery();
            Response.Write("Registration is succesful");
            Response.Write("Administrator.aspx");

            conn.Close();
        }
        catch (SqlException ex)
        {
            Response.Write("Error:"+ex.ToString());
        }
    }

    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }

    protected void DropDownList1cont_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

comm.Parameters.AddWithValue(“@email”,TextBox2EI)行中应该是
TextBox2EI.Text


另外,在
comm.Parameters.AddWithValue(“@country”)行中,DropDownList1cont.SelectedItem.ToString()
我认为您应该传递SelectedItem的文本或值,而不是SelectedItem本身。在电子邮件的参数中,您忘记使用Text属性。
Line 43:             comm.Parameters.AddWithValue("@pass", TextBox3PW.Text);
Line 44:             comm.Parameters.AddWithValue("@country", DropDownList1cont.SelectedItem.ToString());
Line 45:             comm.ExecuteNonQuery();
Line 46:             Response.Write("Registration is succesful");
Line 47:             Response.Write("Administrator.aspx");


 Source File:  c:\Users\user6\Documents\Visual Studio 2015\WebSites\loginPage\Registration.aspx.cs    Line:  45 

Stack Trace: 



[ArgumentException: No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type.]
   System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen, Boolean streamAllowed) +2328239
   System.Data.SqlClient.SqlParameter.GetMetaTypeOnly() +190
   System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc) +16
   System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters, Boolean includeReturnValue) +201
   System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc) +241
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2026
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +375
   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +337
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +192
   Registration.Button1_Click(Object sender, EventArgs e) in c:\Users\user6\Documents\Visual Studio 2015\WebSites\loginPage\Registration.aspx.cs:45
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9692746
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3562