Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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();
Posted
Updated 20-Jul-16 22:17pm
Comments
José Amílcar Casimiro 23-Apr-14 6:00am    
the question is poorly structured.

cmd.Parameters.AddWithValue("@Password", Pass); Is Pass a variable or an object?
[no name] 1-Aug-17 8:42am    
cgstamt = Format(DtItems.Compute("Sum(CGSTValue)", ""), "0.000")
sgstamt = Format(DtItems.Compute("Sum(SGSTValue)", ""), "0.000")
igstamt = Format(DtItems.Compute("Sum(IGSTValue)", ""), "0.000")
[no name] 1-Aug-17 8:44am    
i got error on above code pls suggest what i have to do
"Argument 'Expression' is not a valid value."

Hi,

Your problem resides with this line:
C#
cmd.Parameters.AddWithValue("@Country", DropDownListCountry.SelectedItem);


Change it to:
C#
cmd.Parameters.AddWithValue("@Country", DropDownListCountry.SelectedItem.Value);


Cheers,
JAFC
 
Share this answer
 
v2
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);
 
Share this answer
 
v2
Comments
Adesh Saroha 23-Apr-14 6:06am    
cmd.Parameters.AddWithValue("@Password", Pass.Text);changed but error remains
Sanket Saxena 23-Apr-14 6:12am    
Check Your textbox ID for password and then use it with Text property as same as what you did in TextBoxEmail.Text
I get this message,too but my code is different than yours.
ı looked at some websites but ı could not solve
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900