From your question I understand the issue is error with converting to int.You have to convert subject ID to int before inserting.
Try
{
for (int i = 0; i < listViewSubject.Items.Count; i+=2)
{
string query = "INSERT INTO Std_Subjects (subject_id, std_reg_id) VALUES (" + Int.Parse(listViewSubject.Items[i].Text) + ", " + this.reg_id + ")";
dal.InsertUpdateDelete(query);
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Hope this.reg_id is also int. If not convert it as I converted the subject id. Please note that I have removed single quote from
'" + listViewSubject.Items[i] + "', '" + this.reg_id + "'
This is the method using parameterized query:
for (int i = 0; i < listViewSubject.Items.Count; i+=2)
{
string query = "INSERT INTO Std_Subjects (subject_id, std_reg_id) VALUES (@subjectID,@StdRegId)";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.AddWithValue("@subjectID",Int.Parse(listViewSubject.Items[i].Text));
command.Parameters.AddWithValue("@StdRegId", this.reg_id);
command.ExecuteNonQuery();
}