5
Answers

When i run error occurs

narasiman rao

narasiman rao

12y
1.6k
1
i design the following application as follows;

Name                    txt_name
Employeeid           Textbox2
Dept                    checkboxlist1
                            checkboxlist2

Gender                 Radiobuttionlist1
                             Radiobuttionlist2


DOB                       dropdown

Mobileno                txt_mobile

email                     txt_emailid

Address                 txt_address


I have one insert button.

con = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
        con.Open();
        SqlCommand cmd = new SqlCommand("Reg", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@Empid", TextBox2.Text));
        cmd.Parameters.Add(new SqlParameter("@Name", txt_name.Text));
        cmd.Parameters.Add(new SqlParameter("@Dept", CheckBoxList1.Text));
        cmd.Parameters.Add(new SqlParameter("@Gender", RadioButtonList1.Text));
        cmd.Parameters.Add(new SqlParameter("@DOB", Calendar1.TodaysDate));
        cmd.Parameters.Add(new SqlParameter("@Mobile", txt_mobile.Text));
        cmd.Parameters.Add(new SqlParameter("@Email", txt_emailid.Text));
        cmd.Parameters.Add(new SqlParameter("@Address", txt_address.Text));
        cmd.ExecuteNonQuery();
        con.Close();

Creating Store Procedure code as follows
CREATE Procedure Reg
@Name varchar(50),
@Empid varchar(50),
@Dept varchar(50),
@Gender  varchar(50),
@DOB varchar(50),
@Mobile  int,
@Email Varchar(50),
@Address Varchar(50)
AS  
BEGIN
INSERT INTO Registration VALUES(@Name,@Empid,@Dept,@Gender,@DOB,@Mobile,@Email,@Address)
END
GO

Database  table design as follows;

Name   varchar
        Empid        varchar
        Dept          varchar
        Gender      varchar
        DOB           varchar
        Mobile         int
        Email         varchar
        Address     varchar


WHEN I RUN FOLLOWING ERROR OCCURS AS FOLLOWS;

Error converting data type nvarchar to int.

Answers (5)