コード例 #1
0
ファイル: Form1.cs プロジェクト: ali-d-98/DBMS
        private void button1_Click(object sender, EventArgs e)
        {
            string conString = "data source=DESKTOP-S86R5UP;initial catalog=Ali-2;integrated security=True;MultipleActiveResultSets=True;";

            using (SqlConnection connection = new SqlConnection(conString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(
                           "insert into Person (first_name, last_name, national_id, age, city) values('" + Fname.Text + "', '" + Lname.Text + "', '"
                           + NI.Text + "', '" + Ag.Text + "', '" + Ci.Text + "');",
                           connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        MessageBox.Show("Data inserted");
                        Fname.Text = "";
                        Lname.Text = "";
                        NI.Clear();
                        Ag.Clear();
                        Ci.Clear();
                    }
                }
            }
        }