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?
Deepak SainiPosted Apr 6, 2015, 9:02 AM
if u get Error your make conversion on the insert time.
Usha RajPosted Apr 6, 2015, 8:14 AM
Khargesh RajputPosted Apr 6, 2015, 8:07 AM
set datatype as varchar(50)
Usha RajPosted Apr 6, 2015, 7:59 AM
Khargesh RajputPosted Apr 6, 2015, 7:55 AM
Usha RajPosted Apr 6, 2015, 7:23 AM
Khargesh RajputPosted Apr 6, 2015, 7:17 AM
Usha RajPosted Apr 6, 2015, 7:04 AM
Khargesh RajputPosted Apr 6, 2015, 7:02 AM
varchar datatype used with size
Usha RajPosted Apr 6, 2015, 6:53 AM
Usha RajPosted Apr 6, 2015, 6:52 AM
Khargesh RajputPosted Apr 6, 2015, 6:49 AM
Usha RajPosted Apr 6, 2015, 6:39 AM
this same value I want to add in other table,How I have to do ,can any one suggest me,
Usha RajPosted Apr 6, 2015, 5:45 AM
Khargesh RajputPosted Apr 6, 2015, 5:41 AM
set same datatype as in database and same pass from code behind
Usha RajPosted Apr 6, 2015, 4:57 AM
Gowtham RajamanickamPosted Apr 6, 2015, 4:26 AM
Pranay RanaPosted Apr 6, 2015, 4:14 AM
// 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);
Usha RajPosted Apr 6, 2015, 3:43 AM
Tom MohanPosted Apr 6, 2015, 3:42 AM
The problem is RequirementId has some string(not integer ). System will try to convert that to int. That will throw the error.