PARTHAJEET SAHA

PARTHAJEET SAHA

  • NA
  • 5
  • 4.2k

Error converting data type nvarchar to int.

Jun 17 2014 11:53 AM
Source Error:
 Line 41:             CMD.Parameters.AddWithValue("@ReferenceName", txt_referenceName.Text); 
Line 42:             CMD.Parameters.AddWithValue("@FileUpload", fileName);
 Line 43:             CMD.ExecuteNonQuery();
 Line 44:             con.Close(); 
Line 45:
 .............................................................................................................................................................................
 
Candidate_Add page
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Candidate_Add.aspx.cs" Inherits="Candidate_Candidate_Add" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Candidate Name :
</td>
<td>
<asp:TextBox ID="txt_Candidate_Name" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Profile :
</td>
<td>
<asp:DropDownList ID="ddl_Profile" runat="server">
<asp:ListItem Text="ORACLE" Value="1"></asp:ListItem>
<asp:ListItem Text="JAVA" Value="2"></asp:ListItem>
<asp:ListItem Text="ASP.NET" Value="3"></asp:ListItem>
<asp:ListItem Text="PHP" Value="4"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
E-mail :
</td>
<td>
<asp:TextBox ID="txt_Email" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Gender :
</td>
<td>
<asp:RadioButtonList ID="rdb_Gender" runat="server" RepeatColumns="2">
<asp:ListItem Text="Male" Value="1"></asp:ListItem>
<asp:ListItem Text="Female" Value="2"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
Qualification :
</td>
<td>
<asp:DropDownList ID="ddl_Qualification" runat="server">
<asp:ListItem Text="M-TECH" Value="1"></asp:ListItem>
<asp:ListItem Text="MCA" Value="2"></asp:ListItem>
<asp:ListItem Text="B-TECH" Value="3"></asp:ListItem>
<asp:ListItem Text="BCA" Value="4"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
DOB :
</td>
<td>
<asp:TextBox ID="txt_dob" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Mobile No. :
</td>
<td>
<asp:TextBox ID="txt_Mobile" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Current Salary :
</td>
<td>
<asp:TextBox ID="txt_CurrentSalary" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Current Company :
</td>
<td>
<asp:TextBox ID="txt_CurrentCompany" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Experience :
</td>
<td>
<asp:DropDownList ID="ddl_year" runat="server">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddl_months" runat="server">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
<asp:ListItem Text="6" Value="6"></asp:ListItem>
<asp:ListItem Text="7" Value="7"></asp:ListItem>
<asp:ListItem Text="8" Value="8"></asp:ListItem>
<asp:ListItem Text="9" Value="9"></asp:ListItem>
<asp:ListItem Text="10" Value="10"></asp:ListItem>
<asp:ListItem Text="11" Value="11"></asp:ListItem>
<asp:ListItem Text="12" Value="12"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Reference Name :
</td>
<td>
<asp:TextBox ID="txt_referenceName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Resume Upload :
</td>
<td>
<asp:FileUpload ID="fu_resume" runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btn_Submit" runat="server" Text="Save" OnClick="btn_Submit_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
 
.......................................................................................................................... 
Candidate_Add.aspx.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
public partial class Candidate_Candidate_Add : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Submit_Click(object sender, EventArgs e)
{
con.Open();
int Exp = int.Parse(ddl_year.SelectedValue) * 12 + int.Parse(ddl_months.SelectedValue);
string fileName = Path.GetFileName(fu_resume.PostedFile.FileName);
string Location = Server.MapPath("Resume" + "\\" + fileName);
fu_resume.SaveAs(Location);
SqlCommand CMD = new SqlCommand("SP_Candidate_insert", con);
CMD.CommandType = CommandType.StoredProcedure;
CMD.Parameters.AddWithValue("@CandidateName", txt_Candidate_Name.Text);
CMD.Parameters.AddWithValue("@CandidateProfile", ddl_Profile.SelectedValue);
CMD.Parameters.AddWithValue("@Email", txt_Email.Text);
CMD.Parameters.AddWithValue("@Gender", rdb_Gender.SelectedValue);
CMD.Parameters.AddWithValue("@Qualification", ddl_Qualification.SelectedValue);
CMD.Parameters.AddWithValue("@DOB", txt_dob.Text);
CMD.Parameters.AddWithValue("@MobileNo", txt_Mobile.Text);
CMD.Parameters.AddWithValue("@CurrentSalary", txt_CurrentSalary.Text);
CMD.Parameters.AddWithValue("@CurrentCompany", txt_CurrentCompany.Text);
CMD.Parameters.AddWithValue("@Experience", Exp);
CMD.Parameters.AddWithValue("@ReferenceName", txt_referenceName.Text);
CMD.Parameters.AddWithValue("@FileUpload", fileName);
CMD.ExecuteNonQuery();
con.Close();
}
}
.......................................................................................................................................................
 
Web Config 
 
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="connection" connectionString="Data Source=BABAI_BONY-PC\SQLEXPRESS;Initial catalog=BAJAJ;Integrated Security=True"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
..........................................................................................
Database 
 
CREATE DATABASE BAJAJ
USE BAJAJ
Create Table Candidate
(
Candidate_ID int primary key identity(1,1),
CandidateName nvarchar(50),
CandidateProfile int,
Email nvarchar(50),
Gender int,
Qualification int,
DOB nvarchar(50),
MobileNo int,
CurrentSalary nvarchar(50),
CurrentCompany nvarchar(50),
Experience int,
ReferenceName nvarchar(50),
QualityRate int,
ClosingRate int,
IsDelete int default 0,
FileUpload nvarchar(max)
)
create proc SP_Candidate_insert
(
@CandidateName nvarchar(50),
@CandidateProfile int,
@Email nvarchar(50),
@Gender int,
@Qualification int,
@DOB nvarchar(50),
@MobileNo int,
@CurrentSalary nvarchar(50),
@CurrentCompany nvarchar(50),
@Experience int,
@ReferenceName nvarchar(50),
@FileUpload nvarchar(max)
)
as
begin
insert into Candidate( CandidateName, CandidateProfile, Email, Gender, Qualification, DOB, MobileNo, CurrentSalary, CurrentCompany, Experience, ReferenceName, FileUpload )
values(@CandidateName,@CandidateProfile, @Email, @Gender, @Qualification, @DOB, @MobileNo, @CurrentSalary, @CurrentCompany, @Experience, @ReferenceName, @FileUpload )
end
  I want to know the actual solution of this error. I'll b greatful to u if u kindly help me.
 

Answers (1)