none
Help with ConstraintException RRS feed

  • Question

  • I have two database tables called Doctor and Specialty. The Doctor table has a foreign key constraint with the Specialty table. On my form I have two combo boxes. The first combo box is databound to the Specialty binding source and the second is bound to the fkDoctorSpecialty binding source. This way when you select a specialty in the first combo box a list of matching doctors appears in the second. I have added a query to my doctor table in my dataset called FillByDoctorID. The query looks something like this:

    Code Block

    SELECT doctor.firstname, doctor.lastname, specialty.description

    FROM doctor INNER JOIN specialty ON doctor.specialtyID = specialty.specialtyID

    WHERE doctor.doctorID = @doctorspecialty

     

    This query should only return one record and I want to copy this data elsewhere. I have a button that I will do this. However my program keeps throwing a ConstraintException and highlights the following code:

    Code Block
    doctorTableAdapter1.FillByDoctorID(doctorDetailsDataSet1.Doctor, Convert.ToInt32(cboDoctor.SelectedValue));

     

    I'm not trying to do any data manipulation. This is just a select query. If any of this makes sense and you can point me in the right direction I would appreciate it.

     

     

    Wednesday, December 5, 2007 1:48 AM

All replies

  • At a quick glance, it may seem that you may have used the built in dataset generator.

    Therefore, the Doctor dataset seems to have a foreign key relation to the Speciality table.

     

    You will need to fill the Speciality dataset first in order to satisfy this constraint.

     

    --
    With Regards

    Shailen Sukul
    Software Architect/Developer/Consultant
    (BSc | Mcts (Biztalk (IP))  | Mcpd | Mcts (Web, Win, Dist Apps) | Mcsd.NET | Mcsd | Mcad)
    Ashlen Consulting Services Pty Ltd
    (http://www.ashlen.com.au)

    MSN | Skype | GTalk Id: shailensukul
    Ph:  +61 0421 277 812
    Fax: +61 3 9011 9732
    Linked In: http://www.linkedin.com/in/shailensukul

     

    Wednesday, December 5, 2007 3:59 AM