I am using a viewstate to store the company Ids and splitting at hyphen.
protected void onCompanychange(object sender, EventArgs e)
{
ViewState["companyID"] += companydropdown.SelectedValue + "-";
String companyids = ViewState["companyID"].ToString();
string pattern = "-";
company_array = Regex.Split(companyids, pattern);
company_length = company_array.Length;
}
company array is a string array where i have stored the company ids
the problem is company_array[0] has the initial value of the dropdownlist(company) --select company which is why m getting the error(cannot convert data type nvarchar to int) . I have used the same logic in many places in my project it did not give any error.
Please provide me some solutions
int count = 0;
company_length = company_length - 1;
while (count < GridView3.Rows.Count && compid_counter < company_length )
{
cmd = new SqlCommand("insertWorkDetais", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@trainerId",trainerID);
cmd.Parameters.AddWithValue("@company_Id", company_array[compid_counter]);
cmd.Parameters.AddWithValue("@joined_date", Convert.ToDateTime(GridView3.Rows[count].Cells[1].Text));
cmd.Parameters.AddWithValue("@left_date", Convert.ToDateTime(GridView3.Rows[count].Cells[2].Text));
cmd.ExecuteNonQuery();
count++;
compid_counter++;
}