System.ArgumentException未被用户代码处理 [英] System.ArgumentException was unhandled by user code
问题描述
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings [RegistrationConnectionString]。ConnectionString);
conn.Open();
string insertQuery =Insert into Userdata (用户名,电子邮件,密码,国家/地区)值(@ Username,@ Email,@ Password,@ Country);
SqlCommand cmd = new SqlCommand(insertQuery,conn);
cmd.Parameters.AddWithValue(@ Username,TextBoxUN.Text);
cmd.Parameters.AddWithValue(@ Email,TextBoxEmail.Text);
cmd.Parameters.AddWithValue(@ Password,Pass);
cmd.Parameters.AddWithValue(@ Country,DropDownListCountry.SelectedItem);
< b> 此行的异常System.ArgumentException未被用户代码处理
(对象类型System.Web.UI.WebControls不存在映射) .TextBox到已知的托管提供者本机类型)cmd.ExecuteNonQuery();
Response.Redirect(Manager.aspx);
Response.Write(注册成功);
conn。关闭();
您好,
您的问题在于这一行:
cmd.Parameters.AddWithValue( @ Country ,DropDownListCountry.SelectedItem);
更改为:
cmd .Parameters.AddWithValue( @ Country,DropDownListCountry.SelectedItem.Value);
干杯,
JAFC
检查并更改此行:
cmd.Parameters.AddWithValue(@ Password,Pass);
好像缺少文字属性如果它是ID = Pass的文本框
cmd.Parameters.AddWithValue(@ P assword,Pass.Text);
我也得到了这条消息但是我的代码与你的不同。
$ b $bı看了一些网站但是ı不能解决
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "Insert into Userdata (Username,Email,Password,Country) values (@Username,@Email,@Password,@Country)";
SqlCommand cmd = new SqlCommand(insertQuery, conn);
cmd.Parameters.AddWithValue("@Username", TextBoxUN.Text);
cmd.Parameters.AddWithValue("@Email", TextBoxEmail.Text);
cmd.Parameters.AddWithValue("@Password", Pass);
cmd.Parameters.AddWithValue("@Country", DropDownListCountry.SelectedItem);
Exception on this line System.ArgumentException was unhandled by user code
(No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type) cmd.ExecuteNonQuery();
Response.Redirect("Manager.aspx");
Response.Write("Registration is Successful");
conn.Close();
Hi,
Your problem resides with this line:
cmd.Parameters.AddWithValue("@Country", DropDownListCountry.SelectedItem);
Change it to:
cmd.Parameters.AddWithValue("@Country", DropDownListCountry.SelectedItem.Value);
Cheers,
JAFC
Check and change this line:
cmd.Parameters.AddWithValue("@Password", Pass);
seems like it is missing the text property if it is Textbox with ID=Pass
cmd.Parameters.AddWithValue("@Password", Pass.Text);
I get this message,too but my code is different than yours.
ı looked at some websites but ı could not solve
这篇关于System.ArgumentException未被用户代码处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!