Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code
Please help me urgent

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

public partial class Register : System.Web.UI.Page
{
    
      
    protected void Button1_Click(object sender, EventArgs e)
    {
         SqlConnection con = new SqlConnection();
        con.ConnectionString = WebConfigurationManager.AppSettings["ConnectionString"];
  SqlCommand cmd=new SqlCommand("insert into register values(@name,@address,@password,@confirmpassword)",con);
  
        cmd.Parameters.AddWithValue("@name",TextBox1);
        cmd.Parameters.AddWithValue("@address", TextBox2);
        cmd.Parameters.AddWithValue("@password", TextBox3);
        cmd.Parameters.AddWithValue("@confirmpassword", TextBox4);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
       }
}

Source Error:
error at line 26

Line 24: cmd.Parameters.AddWithValue("@confirmpassword", TextBox4);
Line 25: con.Open();
Line 26: cmd.ExecuteNonQuery();
Line 27: con.Close();
Posted
Updated 26-Jun-18 2:39am
v3
Comments
Member 10347358 24-Nov-13 7:05am    
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.Data;
using System.Configuration;
public partial class Registration : System.Web.UI.Page
{
string str = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{

SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd = new SqlCommand("insert into Login(Uname,LastName,Pass,Usertype,Email,Mobile,CollegeId,CurrentAddress,PermanentAddress,DOB,Gender,Branch,ImageId) values(@1,@2,@3,@5,@6,@7,@8,@,@9,@10,@11,@12,@13,@14)",con);
cmd.Parameters.AddWithValue("@1", TextBox1.Text);
cmd.Parameters.AddWithValue("@2", TextBox2.Text);
cmd.Parameters.AddWithValue("@3", TextBox3.Text);
cmd.Parameters.AddWithValue("@5", DropDownList1.SelectedValue);
cmd.Parameters.AddWithValue("@6", TextBox4.Text);
cmd.Parameters.AddWithValue("@7", TextBox5.Text);
cmd.Parameters.AddWithValue("@8", TextBox6.Text);
cmd.Parameters.AddWithValue("@9", TextBox7.Text);
cmd.Parameters.AddWithValue("@10", TextBox8.Text);
cmd.Parameters.AddWithValue("@11", Calendar1.SelectedDate.ToShortDateString());
cmd.Parameters.AddWithValue("@12", CheckBoxList1.SelectedValue);
cmd.Parameters.AddWithValue("@13", DropDownList2.SelectedValue);
if(FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("~/images/")+FileUpload1.FileName);
}
cmd.Parameters.AddWithValue("@14",FileUpload1.FileName );
int j=cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");

}
}
Member 10347358 24-Nov-13 7:06am    
Anyone please tell me the error i just can't get it
and getting this error again and again
No mapping exists from object type System.Web.UI.WebControls.RadioButtonList to a known managed provider native type

Member 14935968 29-Sep-20 12:06pm    
Have get the solution?

please change your code as follows....

C#
cmd.Parameters.AddWithValue("@name",TextBox1.Text);
cmd.Parameters.AddWithValue("@address", TextBox2.Text);
cmd.Parameters.AddWithValue("@password", TextBox3.Text);
cmd.Parameters.AddWithValue("@confirmpassword", TextBox4.Text);


Regards
Sebastian
 
Share this answer
 
Comments
amperayani 4-Jun-12 8:12am    
thanks i got it
Member 10860948 13-Jul-14 3:17am    
Thanks i also got it.....
:-)

From:
Pragnesh P. Patel- P3
you have to set the text of a texbox not a control,

the correct is:
C#
cmd.Parameters.AddWithValue("@name",TextBox1.Text);
 
Share this answer
 
Comments
Sebastian T Xavier 4-Jun-12 8:17am    
already solved :D
taha bahraminezhad Jooneghani 4-Jun-12 8:51am    
when i press the add solution button there isn't a solution only 6min:)
god damn google+ because distracts me!:)

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