Am trying to add the table column value into another table ,the column data type is varchar(.i.e QQ20150001),but while adding into another table am getting the error like "Error Converting nvarchar to int"
my code is:
page.DAL
public void SaveData(string JobTitle, string RequiredExp,string JobLocation,int RegistrationId,string RequirementId)
{
SqlConnection con = dbcon.OpenCoonection( );
SqlCommand cmd = new SqlCommand("USP_InsertSavedJobs", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@JobTitle", JobTitle);
cmd.Parameters.Add("@RequiredExp", RequiredExp);
cmd.Parameters.Add("@JobLocation", JobLocation);
cmd.Parameters.AddWithValue("@RegId", RegistrationId);
cmd.Parameters.Add("@RequirementId", RequirementId);// Am getting the this value from other table by using session
cmd.ExecuteNonQuery();
dbcon.CloseConnection();
}
Can any one tell me what's going wrong?

Tom MohanRank #912 · 2.3K reputationPosted Apr 5, 2015, 11:42 PM EDT
The problem is RequirementId has some string(not integer ). System will try to convert that to int. That will throw the error.
Usha Raj145 reputationPosted Apr 5, 2015, 11:43 PM EDT
Pranay RanaRank #735 · 3.2K reputationPosted Apr 6, 2015, 12:14 AM EDT
// Add the input parameter and set its properties.
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@RegId";
parameter.SqlDbType = SqlDbType.NVarChar;
parameter.Direction = ParameterDirection.Input;
parameter.Value = RegistrationId.ToString();
// Add the parameter to the Parameters collection.
cmd.Parameters.Add(parameter);
Gowtham RajamanickamRank #57 · 29K reputationPosted Apr 6, 2015, 12:26 AM EDT
Usha Raj145 reputationPosted Apr 6, 2015, 12:57 AM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Apr 6, 2015, 1:41 AM EDT
set same datatype as in database and same pass from code behind
Usha Raj145 reputationPosted Apr 6, 2015, 1:45 AM EDT
Usha Raj145 reputationPosted Apr 6, 2015, 2:39 AM EDT
this same value I want to add in other table,How I have to do ,can any one suggest me,
Khargesh RajputRank #616 · 3.9K reputationPosted Apr 6, 2015, 2:49 AM EDT
Usha Raj145 reputationPosted Apr 6, 2015, 2:52 AM EDT
Usha Raj145 reputationPosted Apr 6, 2015, 2:53 AM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Apr 6, 2015, 3:02 AM EDT
varchar datatype used with size
Usha Raj145 reputationPosted Apr 6, 2015, 3:04 AM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Apr 6, 2015, 3:17 AM EDT
Usha Raj145 reputationPosted Apr 6, 2015, 3:23 AM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Apr 6, 2015, 3:55 AM EDT
Usha Raj145 reputationPosted Apr 6, 2015, 3:59 AM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Apr 6, 2015, 4:07 AM EDT
set datatype as varchar(50)
Usha Raj145 reputationPosted Apr 6, 2015, 4:14 AM EDT
Deepak SainiRank #2,411 · 586 reputationPosted Apr 6, 2015, 5:02 AM EDT
if u get Error your make conversion on the insert time.