1
Answer

Foreign key data deleting error in ADO.NET Application

Ask a question
Bineesh  VP

Bineesh VP

10y
1.4k
1
Sir, I am in the midst of a Data Deleting problem as it a foreign key.

Below the table where getting problem when delete data:-

 tbl-Class                                               tbl_Division
------------                                          ----------------
classId                                                    divisionId
className                                               divisionName
noOfSeats                                                   classId



I cannot delete data from tbl_Class as I getting the error in below :-

Form.cs code:-



SP Class code :-

public int ClassDelete(classInfo infoClass)
        {
            
            try
            {
                if (sqlCon.State == ConnectionState.Closed)
                {
                    sqlCon.Open();
                }
                SqlCommand cmd = new SqlCommand("ClassDelete", sqlCon);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("classId", SqlDbType.Int).Value = infoClass.classId;
                int inCount = cmd.ExecuteNonQuery();
                if (inCount > 0)
                {
                    MessageBox.Show("Deleted Successfully", "School Automation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return inCount;
            }
            catch (Exception)
            {
               
                throw;
            }
          
        }
Please tell how can overcome this error.  

Answers (1)