none
Relations multiple table using in C# RRS feed

  • Question

  • Hi All ...

    I have 3 tables and i can't relations . in fact  I carry out relations separately ogretmen to program or program to nobet . if I want to all together gives an error. My code like this...

    public void vt_iliski()
          {
              try
             {
                 string sorgu_ogretmen = "select * from ogretmen";
                 string sorgu_program = "select * from program";
                 string sorgu_nobet = "select * from nobet";


                 ds_gnd = new DataSet();
                 DataTable tablo = new DataTable();
                 adpt_ogrt = new SqlCeDataAdapter(sorgu_ogretmen, baglan());
                 adpt_prg = new SqlCeDataAdapter(sorgu_program, baglan());
                 adpt_nbt = new SqlCeDataAdapter(sorgu_nobet, baglan());

                 adpt_ogrt.Fill(ds_gnd, "ogretmen");
                 adpt_prg.Fill(ds_gnd, "program");
                 adpt_nbt.Fill(ds_gnd, "nobet");

                    /*  **********  relation -1 ****************** */

                 DataColumn ogrt_kolon = ds_gnd.Tables["ogretmen"].Columns["ogrt_ID"];
                 DataColumn prg_kolon = ds_gnd.Tables["program"].Columns["ogrt_ID"];
              
                 iliski1 = new DataRelation("Ogretmen_To_Program", ogrt_kolon, prg_kolon);

                 
                 ForeignKeyConstraint kisitla = new ForeignKeyConstraint(ogrt_kolon, prg_kolon);

                 kisitla.UpdateRule = Rule.Cascade;
                 kisitla.DeleteRule = Rule.Cascade;
                 kisitla.AcceptRejectRule = AcceptRejectRule.Cascade;

                 ds_gnd.Tables["program"].Constraints.Add(kisitla);
                 ds_gnd.EnforceConstraints = true;
           
                  ds_gnd.Relations.Add(iliski1);
                
                 yonet_ogrt = new BindingSource(ds_gnd, ds_gnd.Tables["ogretmen"].ToString());
                 yonet_prg = new BindingSource(yonet_ogrt, "Ogretmen_To_Program");

              

                 /*  **********  relation-2 ****************** */
                      DataColumn prg_kolon_nobet = ds_gnd.Tables["program"].Columns["prg_ID"];              
                  DataColumn nobet_kolon = ds_gnd.Tables["nobet"].Columns["prg_ID"];
                
                iliski2 = new DataRelation("Program_To_nobet",prg_kolon_nobet , nobet_kolon );


        ForeignKeyConstraint kisitla2 = new ForeignKeyConstraint(prg_kolon_nobet, nobet_kolon);


                  kisitla2.UpdateRule = Rule.Cascade;
                  kisitla2.DeleteRule = Rule.Cascade;
                  kisitla2.AcceptRejectRule = AcceptRejectRule.Cascade;

                  ds_gnd.Tables["nobet"].Constraints.Add(kisitla2);
                  ds_gnd.EnforceConstraints = true;
               
                  ds_gnd.Relations.Add(iliski2);

                  yonet_prg = new BindingSource(ds_gnd, ds_gnd.Tables["Program"] .ToString());
                  
                  yonet_nbt = new BindingSource(yonet_prg  , "Program_To_nobet");
                    
               }
             catch (Exception hata)
             {
                 MessageBox.Show("Okul Günlük Nöbet Defteri iliskilendirme Hatasi olustu : " + hata.Message + " " + hata.StackTrace );

             }
                        
             finally
             {
                 baglanti.Dispose();
                 adpt_ogrt.Dispose();
                 adpt_prg.Dispose();
                 adpt_nbt.Dispose();
                    
             }

    Sunday, November 11, 2012 1:21 PM

All replies

  • Hi YBG,

    Welcome to the MSDN forum.

    Could you please let me know where the error occurs?

    What is the specific error message?

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, November 13, 2012 7:16 AM
  • hi Alexander .. in my form app. i have textboxs related databindings yonet_ogrt and I have 2 datagridview yonet_prg

    and yonet_nbt.. so  I want to all together navigate but  textboxs and datagridview related yonet_prg is working but

    datagridview  related yonet_nbt not working...  this is my trouble...

    Tuesday, November 13, 2012 10:14 AM
  • Hi YBG,

    I check your code on my side. It works OK. Could you please let me know the specific behavior on your side?

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, November 14, 2012 9:36 AM
  • And also, what is the error you're getting?

    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Sunday, November 18, 2012 5:24 PM