Beispiel #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            SqlConn.OpenConn();
            dataSet            = new DataSet();
            bindingSourceFirst = new BindingSource();


            dataAdapterFirst  = new SqlDataAdapter(ConfigurationManager.AppSettings.Get("selectAllFromParent"), SqlConn.connection);
            dataAdapterSecond = new SqlDataAdapter(ConfigurationManager.AppSettings.Get("selectAllFromChildren"), SqlConn.connection);
            commandBuilder    = new SqlCommandBuilder(dataAdapterSecond);

            dataAdapterFirst.Fill(dataSet, ConfigurationManager.AppSettings.Get("ParentTable"));
            dataAdapterSecond.Fill(dataSet, ConfigurationManager.AppSettings.Get("ChildTable"));

            DataRelation dr = new DataRelation(ConfigurationManager.AppSettings.Get("FkServ"),
                                               dataSet.Tables[ConfigurationManager.AppSettings.Get("ParentTable")]
                                               .Columns[ConfigurationManager.AppSettings.Get("FK")],
                                               dataSet.Tables[ConfigurationManager.AppSettings.Get("ChildTable")]
                                               .Columns[ConfigurationManager.AppSettings.Get("FK")]);

            dataSet.Relations.Add(dr);

            bindingSourceFirst = new BindingSource
            {
                DataSource = dataSet,
                DataMember = ConfigurationManager.AppSettings.Get("ParentTable")
            };

            bindingSourceSecond            = new BindingSource();
            bindingSourceSecond.DataSource = bindingSourceFirst;
            bindingSourceSecond.DataMember = ConfigurationManager.AppSettings.Get("FkServ");

            GridFirst.DataSource  = bindingSourceFirst;
            GridSecond.DataSource = bindingSourceSecond;
        }
Beispiel #2
0
        public static void ConnectionState()
        {
            string            msg   = "Connection state: " + "The connection is ";
            string            title = SqlConn.myApp();
            MessageBoxButtons btn   = MessageBoxButtons.OK;
            MessageBoxIcon    icon  = MessageBoxIcon.Information;

            MessageBox.Show(msg + connection.State.ToString(), title, btn, icon);
        }
Beispiel #3
0
 public static void OpenConn()
 {
     connection.Close();
     try
     {
         connection.ConnectionString = SqlConn.GetConnectionString();
         connection.Open();
     }
     catch (Exception e)
     {
         MessageBox.Show("The sysyem failed to establish a connection." + Environment.NewLine + e);
     }
     //finally
     //{
     //    ConnectionState();
     //}
 }
Beispiel #4
0
 public Form1()
 {
     InitializeComponent();
     this.Text = SqlConn.myApp();
 }
Beispiel #5
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     SqlConn.CloseConn();
 }