示例#1
0
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlConnection MeinConnection = Mein.CreateConnection((string)comboBox1.SelectedItem);

            MeinConnection.Open();

            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();

            for (int i = 0; i < dataSet.Tables.Count; i++)
            {
                sqlDataAdapter = new SqlDataAdapter($"SELECT * FROM {dataSet.Tables[i].TableName}", MeinConnection);
                sqlDataAdapter.Fill(dataSet.Tables[i]);
            }
            dataGridView1.DataSource = dataSet.Tables[comboBox2.SelectedIndex];
        }
示例#2
0
        //public string serverName;

        public Form1()
        {
            InitializeComponent();

            SqlConnection MeinConnection = Mein.CreateConnection("master");

            MeinConnection.Open();

            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            SqlCommand     sqlCommand     = new SqlCommand();
            SqlDataReader  sqlDataReader;

            #region Не валидное имя сервера
            //sqlCommand = new SqlCommand($"SELECT @@servername", MeinConnection);
            //sqlDataReader = sqlCommand.ExecuteReader();
            //while (sqlDataReader.Read())
            //{
            //    serverName = (string)sqlDataReader.GetValue(0);
            //    Console.WriteLine(serverName);
            //}
            //sqlCommand.Cancel();
            //sqlDataReader.Close();
            #endregion

            //Вывод всех таблиц в dataGridView
            sqlDataAdapter = new SqlDataAdapter("EXEC sp_helpdb", MeinConnection);
            //sqlDataAdapter = new SqlDataAdapter($"EXEC sp_Databases", MeinConnection);
            DataTable table = new DataTable();
            sqlDataAdapter.Fill(table);
            dataGridView1.DataSource = table;

            Console.WriteLine(MeinConnection.Database);
            label1.Text = MeinConnection.Database;

            sqlCommand    = new SqlCommand("EXEC sp_helpdb", MeinConnection);
            sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                comboBox1.Items.Add(sqlDataReader.GetValue(0));
            }
        }
示例#3
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox2.Items.Clear();
            comboBox2.Text = "";
            dataSet.Tables.Clear();

            SqlConnection MeinConnection = Mein.CreateConnection((string)comboBox1.SelectedItem);

            MeinConnection.Open();

            SqlCommand    sqlCommand = new SqlCommand();
            SqlDataReader sqlDataReader;

            sqlCommand    = new SqlCommand($"SELECT TABLE_NAME FROM {comboBox1.SelectedItem}.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'", MeinConnection);
            sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                comboBox2.Items.Add(sqlDataReader.GetValue(0));
                dataSet.Tables.Add((string)sqlDataReader.GetValue(0));
            }
            sqlCommand.Cancel();
            sqlDataReader.Close();
        }
示例#4
0
        public Form1()
        {
            InitializeComponent();
            SqlConnection MeinConnection = Mein.CreateConnection();

            MeinConnection.Open();

            Mein.CreateTable("Students", dataSet);
            Mein.CreateTable("Specials", dataSet);

            DataTable Students = dataSet.Tables[0],
                      Specials = dataSet.Tables[1];

            dataGridView1.DataSource = Students;
            dataGridView2.DataSource = Specials;

            dataSet.Relations.Add("Specials_Students", Specials.Columns[0], Students.Columns[4]);
            Students.PrimaryKey = new DataColumn[] { Students.Columns[0] };
            Specials.PrimaryKey = new DataColumn[] { Specials.Columns[0] };
            ForeignKeyConstraint Key = new ForeignKeyConstraint(Specials.Columns[0], Students.Columns[4]);

            Key.DeleteRule = Rule.Cascade;



            #region Добавление записей
            //SqlCommand MeineStudent = new SqlCommand();

            //MeineStudent = new SqlCommand("DELETE FROM Students", MeinConnection);
            //MeineStudent.ExecuteNonQuery();
            //string[] data = new string[5]
            //{
            //"INSERT INTO Students (Id, Name, Surname, Phone, Id_Special) Values ('1','" + CreateName() + "','" + CreateName() + "','" + CreatePhone() + "','" + CreateSpecials() + "')",
            //"INSERT INTO Students (Id, Name, Surname, Phone, Id_Special) Values ('2','" + CreateName() + "','" + CreateName() + "','" + CreatePhone() + "','" + CreateSpecials() + "')",
            //"INSERT INTO Students (Id, Name, Surname, Phone, Id_Special) Values ('3','" + CreateName() + "','" + CreateName() + "','" + CreatePhone() + "','" + CreateSpecials() + "')",
            //"INSERT INTO Students (Id, Name, Surname, Phone, Id_Special) Values ('4','" + CreateName() + "','" + CreateName() + "','" + CreatePhone() + "','" + CreateSpecials() + "')",
            //"INSERT INTO Students (Id, Name, Surname, Phone, Id_Special) Values ('5','" + CreateName() + "','" + CreateName() + "','" + CreatePhone() + "','" + CreateSpecials() + "')"
            //};
            //foreach (var a in data)
            //{
            //    MeineStudent = new SqlCommand(a, MeinConnection);
            //    MeineStudent.ExecuteNonQuery();
            //}

            //MeineStudent = new SqlCommand("DELETE FROM Specials", MeinConnection);
            //MeineStudent.ExecuteNonQuery();
            //string[] dataa = new string[4]
            //{
            //"INSERT INTO Specials (Id, Depatment, Special) Values ('1','Programming','PO')",
            //"INSERT INTO Specials (Id, Depatment, Special) Values ('2','Technical','ATP')",
            //"INSERT INTO Specials (Id, Depatment, Special) Values ('3','Economy','BU')",
            //"INSERT INTO Specials (Id, Depatment, Special) Values ('4','Programming','PI')"
            //};
            //foreach (var a in dataa)
            //{
            //    MeineStudent = new SqlCommand(a, MeinConnection);
            //    MeineStudent.ExecuteNonQuery();
            //}
            #endregion


            //dataSet.WriteXmlSchema(@"C:\Users\right\Documents\Visual Studio 2017\Projects\Mein_1\XML\Schema.xml");
            //dataSet.WriteXml(@"C:\Users\right\Documents\Visual Studio 2017\Projects\Mein_1\XML\Data.xml");
        }