-2
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)
{
}
}
- のマッピングが知られている管理プロバイダのネイティブ型にオブジェクト型System.Web.UI.WebControls.TextBox から存在していません。
説明:
説明:未処理の例外が現在のWeb要求の実行中に発生しました。エラーの詳細とコード内のどこで発生したのかについては、スタックトレースを参照してください。
例外の詳細:System.ArgumentException:オブジェクト型System.Web.UI.WebControls.TextBoxから既知の管理プロバイダーのネイティブ型へのマッピングが存在しません。
ソースエラー:それはTextBox2EI.Text
あるべきcomm.Parameters.AddWithValue("@email", TextBox2EI);
ラインで
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
電子メールのパラメータで、Textプロパティを使用するのを忘れました。 – Steve